Archived
1

Pokememe deletion command

This commit is contained in:
Vladimir Hodakov 2017-12-04 23:14:41 +04:00
parent 8af37b6c34
commit fa71616a14
4 changed files with 63 additions and 3 deletions

View File

@ -19,11 +19,11 @@ func (f *Forwarder) ProcessForward(update *tgbotapi.Update, playerRaw *dbmapping
switch {
case pokememeMsg.MatchString(text):
c.Log.Debug("Pokememe posted!")
if playerRaw.LeagueID == 1 {
if c.Users.PlayerBetterThan(playerRaw, "admin") {
return c.Pokedexer.ParsePokememe(update, playerRaw)
} else {
return c.Talkers.AnyMessageUnauthorized(update)
}
return c.Talkers.AnyMessageUnauthorized(update)
case profileMsg.MatchString(text):
c.Log.Debug("Profile posted!")
return c.Users.ParseProfile(update, playerRaw)

52
lib/pokedexer/cleaners.go Normal file
View File

@ -0,0 +1,52 @@
// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package pokedexer
import (
"github.com/go-telegram-bot-api/telegram-bot-api"
"strconv"
)
// DeletePokememe deletes pokememe by its ID
func (p *Pokedexer) DeletePokememe(update *tgbotapi.Update) string {
pokememeNum, _ := strconv.Atoi(update.Message.CommandArguments())
if pokememeNum == 0 {
return "fail"
}
pokememe, ok := p.GetPokememeByID(strconv.Itoa(pokememeNum))
if !ok {
return "fail"
}
_, err := c.Db.NamedExec("DELETE FROM pokememes WHERE id=:id", &pokememe.Pokememe)
if err != nil {
c.Log.Error(err.Error())
return "fail"
}
_, err = c.Db.NamedExec("DELETE FROM pokememes_elements WHERE pokememe_id=:id", &pokememe.Pokememe)
if err != nil {
c.Log.Debug(err.Error())
}
_, err = c.Db.NamedExec("DELETE FROM pokememes_locations WHERE pokememe_id=:id", &pokememe.Pokememe)
if err != nil {
c.Log.Debug(err.Error())
}
_, err = c.Db.NamedExec("DELETE FROM profiles_pokememes WHERE pokememe_id=:id", &pokememe.Pokememe)
if err != nil {
c.Log.Debug(err.Error())
}
message := "Покемем удалён."
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
msg.ParseMode = "Markdown"
c.Bot.Send(msg)
return "ok"
}

View File

@ -18,4 +18,6 @@ type PokedexerInterface interface {
GetPokememes() ([]dbmapping.PokememeFull, bool)
GetPokememeByID(pokememeID string) (dbmapping.PokememeFull, bool)
DeletePokememe(update *tgbotapi.Update) string
}

View File

@ -64,6 +64,12 @@ func (r *Router) routePrivateRequest(update *tgbotapi.Update, playerRaw *dbmappi
case pokememeInfoMsg.MatchString(text):
c.Pokedexer.PokememeInfo(update, playerRaw)
return "ok"
case update.Message.Command() == "delete_pokememe":
if c.Users.PlayerBetterThan(playerRaw, "owner") {
return c.Pokedexer.DeletePokememe(update)
}
return c.Talkers.AnyMessageUnauthorized(update)
case update.Message.Command() == "me":
if playerRaw.ID != 0 {
c.Users.ProfileMessage(update, playerRaw)