golearn

package module
v0.0.0-...-56f048d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2020 License: GPL-3.0 Imports: 7 Imported by: 0

README

Build Status Go Report Card Coverage Status

GoLearn

GoLearn - Bot For Learning New Words Via Telegram / KakaoTalk

Documentation

Index

Constants

View Source
const ModePicking = "picking"

ModePicking constant for user "picking" mode

View Source
const ModeTyping = "typing"

ModeTyping constant for user "typing" mode

Variables

This section is empty.

Functions

func LogFatal

func LogFatal(err error, message string)

LogFatal prints error message with stack trace with exited program.

func LogPrint

func LogPrint(err error, message string)

LogPrint prints error message with stack trace without exited program.

func LogPrintf

func LogPrintf(err error, message string, args ...interface{})

LogPrintf prints error message with stack trace. Arguments are handled in the manner of fmt.Printf.

Types

type Activity

type Activity struct {
	UserID    string
	State     State
	Answer    string
	IsRight   bool
	Timestamp time.Time
}

Activity represents user activity.

type Category

type Category struct {
	Name  string
	Words int
}

Category represents category model.

type Config

type Config struct {
	Env             string   `json:"env"`
	Database        Database `json:"database"`
	DefaultLanguage string   `json:"default_language"`
}

Config ...

func ConfigFromEnv

func ConfigFromEnv() *Config

ConfigFromEnv returns config based on environment variables

type DBService

type DBService interface {
	RandomQuestion(category string) (Row, error)
	RandomAnswers(q Row, limit int) ([]Row, error)
	SetState(State) error
	GetState(string) (State, error)
	ResetState(string) error
	InsertWord(Row) error
	InsertUser(user User) error
	UpdateUser(user User) error
	ExistUser(user User) (bool, error)
	GetUser(userID string) (User, error)
	SetUserMode(userID string, mode string) error
	GetCategories(userID string) ([]Category, error)
	SetUserCategory(userID string, category string) error
	DeleteWordsByCategory(userID string, category string) error
	InsertActivity(activity Activity) error
	GetStatistics(userID string, year int, month int, week int, day int) (Statistics, error)
	Close()
}

DBService ...

type Database

type Database struct {
	Host     string `json:"host"`
	Port     string `json:"port"`
	User     string `json:"user"`
	Name     string `json:"name"`
	Password string `json:"password"`
	Delay    int    `json:"delay"`
}

Database ...

type HTTPService

type HTTPService interface {
	Send(update *Update, message string, keyboard string) error
	Parse(r *http.Request) (*Update, error)
}

HTTPService represents interface for dealing with sending and parsing http requests

type Language

type Language map[string]string

Language represents collection of phrases by certain language used in application

func GetLanguage

func GetLanguage(content []byte) (Language, error)

GetLanguage returns language object with phrases

type LogFormatter

type LogFormatter struct{}

LogFormatter ...

type Row

type Row struct {
	ID        int `bson:"-"`
	Word      string
	Translate string
	Category  string
}

Row ...

type StatRow

type StatRow struct {
	Total int `json:"total"`
	Right int `json:"right"`
	Wrong int `json:"wrong"`
}

StatRow represents user statistics for specific period.

type State

type State struct {
	UserKey   string
	Question  Row
	Answers   []Row
	Mode      string
	Category  string
	Timestamp int64
}

State represents last user state by saving question and answers in db. When user answers we get last state and compare text user send with state answer

type Statistics

type Statistics struct {
	Today StatRow `json:"today"`
	Week  StatRow `json:"week"`
	Month StatRow `json:"month"`
}

Statistics represents group of periods.

type Update

type Update struct {
	ChatID   string
	UserID   string
	Username string
	Name     string
	Message  string
}

Update represents joint response data model from service (telegram, kakaotalk). Contains minimal required data for detecting user and sending message back.

type User

type User struct {
	UserID   string
	Username string
	Name     string
	Mode     string
	Category string
}

User represents user model

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL