Chat table for db
This commit is contained in:
parent
5f6eb05881
commit
45049a0c84
|
@ -7,10 +7,10 @@ import (
|
|||
var commandMe = neco.NewCommand("me", "Пишу ваш текст о вас в третьем лице", false)
|
||||
var commandHelp = neco.NewCommand("help", "Показываю данный текст", false)
|
||||
var commandSay = neco.NewCommand("say", "Пишу ваш текст от своего имени.", true)
|
||||
var commandWarn = neco.NewCommand("warn", "Делаю предупреждение пользователю", true)
|
||||
var commandFeed = neco.NewCommand("subscribe", "Регистрирую данный чат в качестве получателя рассылки", true)
|
||||
var commandFeedUnsub = neco.NewCommand("unsubscribe", "Удаляю данный чат из рассылки", true)
|
||||
var commandTop = neco.NewCommand("top", "Показываю ТОП-10 пользователей по числу кармы", false)
|
||||
|
||||
var defaultCommands = []*neco.Command{commandHelp, commandMe}
|
||||
var adminCommands = []*neco.Command{commandSay, commandWarn, commandFeed}
|
||||
var defaultCommands = []*neco.Command{commandHelp, commandMe, commandTop}
|
||||
var adminCommands = []*neco.Command{commandSay, commandFeed, commandFeed, commandFeedUnsub}
|
||||
var allCommands = append(defaultCommands, adminCommands...)
|
||||
|
|
1
main.go
1
main.go
|
@ -29,6 +29,7 @@ func main() {
|
|||
neco := nechotron.NewTron(token, &MainState)
|
||||
neco.
|
||||
Use(UserDBUpdater(db)).
|
||||
Use(ChatUpdate(db)).
|
||||
Use(ErrorLogger).
|
||||
Use(ExecTimeLogger)
|
||||
api := echotron.NewAPI(token)
|
||||
|
|
|
@ -28,6 +28,42 @@ func UserLogger(next nechotron.UpdateHandler) nechotron.UpdateHandler {
|
|||
}
|
||||
}
|
||||
|
||||
func ChatUpdate(db *tongo.Database) nechotron.Middleware {
|
||||
return func(next nechotron.UpdateHandler) nechotron.UpdateHandler {
|
||||
return func(u *nechotron.Update) error {
|
||||
if u.Message == nil {
|
||||
return next(u)
|
||||
}
|
||||
chats := tongo.NewStore[Chat](db)
|
||||
config := tongo.NewStore[Config](db)
|
||||
chat := u.Message.Chat
|
||||
res, err := chats.GetOne(u.Ctx, tongo.E("id", chat.ID))
|
||||
if err != nil {
|
||||
addNewChats, err := config.GetOne(u.Ctx, tongo.E("name", "newchats"))
|
||||
if err != nil {
|
||||
addNewChats = &Config{
|
||||
Item: tongo.NewID(),
|
||||
Name: "newchats",
|
||||
Value: true,
|
||||
}
|
||||
config.InsertOne(u.Ctx, addNewChats)
|
||||
}
|
||||
addNew := addNewChats.Value.(bool)
|
||||
if !addNew {
|
||||
return nil
|
||||
}
|
||||
res = &Chat{
|
||||
Item: tongo.NewID(),
|
||||
ID: chat.ID,
|
||||
Title: chat.Title,
|
||||
}
|
||||
chats.InsertOne(u.Ctx, res)
|
||||
}
|
||||
return next(u)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func UserDBUpdater(db *tongo.Database) nechotron.Middleware {
|
||||
return func(next nechotron.UpdateHandler) nechotron.UpdateHandler {
|
||||
return func(u *nechotron.Update) error {
|
||||
|
|
5
rss.go
5
rss.go
|
@ -54,11 +54,10 @@ func ParseRSS(api *echotron.API) {
|
|||
author := "by " + item.Author.Name
|
||||
desc := item.Description
|
||||
translator := InitTranslator()
|
||||
translates, err := translator.Translate("ru", item.Title, "by "+item.Author.Name, item.Description)
|
||||
translates, err := translator.Translate("ru", item.Title, item.Description)
|
||||
if err == nil {
|
||||
title = translates[0]
|
||||
author = translates[1]
|
||||
desc = translates[2]
|
||||
desc = translates[1]
|
||||
}
|
||||
text := fmt.Sprintf(text_template,
|
||||
nechotron.EscapeMd2(title),
|
||||
|
|
9
types.go
9
types.go
|
@ -52,6 +52,14 @@ var userIndex = mongo.IndexModel{
|
|||
|
||||
func (User) Coll() string { return "users" }
|
||||
|
||||
type Chat struct {
|
||||
tongo.Item `bson:",inline"`
|
||||
ID int64
|
||||
Title string
|
||||
}
|
||||
|
||||
func (Chat) Coll() string { return "chats" }
|
||||
|
||||
var _ tongo.Collectable = &KarmaShot{}
|
||||
|
||||
type KarmaShot struct {
|
||||
|
@ -113,6 +121,7 @@ type FeedChat struct {
|
|||
Title string
|
||||
ChatID int64
|
||||
ThreadID int
|
||||
Language string
|
||||
}
|
||||
|
||||
func (FeedChat) Coll() string { return "feed_chats" }
|
||||
|
|
Loading…
Reference in New Issue