Archived
1

Initial commit

This commit is contained in:
Vladimir Hodakov
2017-10-04 17:56:18 +04:00
commit 4fec8f0fe7
14 changed files with 449 additions and 0 deletions

26
lib/router/exported.go Normal file
View File

@@ -0,0 +1,26 @@
// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package router
import (
// stdlib
"log"
// local
"../appcontext"
)
var (
c *appcontext.Context
r *Router
)
func New(ac *appcontext.Context) {
c = ac
rh := RouterHandler{}
c.RegisterRouterInterface(rh)
}
func (r *Router) Init() {
log.Printf("Initialized request router...")
}

19
lib/router/handler.go Normal file
View File

@@ -0,0 +1,19 @@
// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package router
import (
// 3rd party
"gopkg.in/telegram-bot-api.v4"
)
type RouterHandler struct {}
func (rh RouterHandler) Init() {
r.Init()
}
func (rh RouterHandler) RouteRequest(update tgbotapi.Update) string {
return r.RouteRequest(update)
}

51
lib/router/router.go Normal file
View File

@@ -0,0 +1,51 @@
// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package router
import (
// stdlib
"log"
"regexp"
// 3rd party
"gopkg.in/telegram-bot-api.v4"
// local
"../talkers"
)
type Router struct {}
// This function will route requests to appropriative modules
// It will return "ok" or "fail"
// If command doesn't exist, it's "fail"
func (r *Router) RouteRequest(update tgbotapi.Update) string {
text := update.Message.Text
// Regular expressions
var durakMsg = regexp.MustCompile("(Д|д)(У|у)(Р|р)(А|а|Е|е|О|о)")
var huMsg = regexp.MustCompile("(Х|х)(У|у)(Й|й|Я|я|Ю|ю|Е|е)")
var blMsg = regexp.MustCompile("\\s(Б|б)(Л|л)(Я|я)(Т|т|Д|д)")
var ebMsg = regexp.MustCompile("(Е|е|Ё|ё)(Б|б)(\\s|А|а|Т|т|У|у|Е|е|Ё|ё|И|и)")
var piMsg = regexp.MustCompile("(П|п)(И|и)(З|з)(Д|д)")
var helpMsg = regexp.MustCompile("/help\\z")
switch {
case helpMsg.MatchString(text):
talkers.HelpMessage(c.Bot, update)
case huMsg.MatchString(text):
talkers.MatMessage(c.Bot, update)
case blMsg.MatchString(text):
talkers.MatMessage(c.Bot, update)
case ebMsg.MatchString(text):
talkers.MatMessage(c.Bot, update)
case piMsg.MatchString(text):
talkers.MatMessage(c.Bot, update)
case durakMsg.MatchString(text):
talkers.DurakMessage(c.Bot, update)
default:
log.Printf("User posted unknown command.")
return "fail"
}
return "ok"
}

View File

@@ -0,0 +1,14 @@
// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package routerinterface
import (
// 3rd party
"gopkg.in/telegram-bot-api.v4"
)
type RouterInterface interface {
Init()
RouteRequest(update tgbotapi.Update) string
}