2020-05-30 08:35:45 +00:00
|
|
|
package discord
|
|
|
|
|
2020-06-06 12:28:45 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2021-05-06 12:42:37 +00:00
|
|
|
"github.com/tribalwarshelp/shared/tw/twmodel"
|
|
|
|
"github.com/tribalwarshelp/shared/tw/twurlbuilder"
|
2020-06-06 12:28:45 +00:00
|
|
|
"strconv"
|
2021-01-08 19:15:11 +00:00
|
|
|
"strings"
|
2020-06-06 12:28:45 +00:00
|
|
|
|
2021-01-08 19:15:11 +00:00
|
|
|
"github.com/tribalwarshelp/golang-sdk/sdk"
|
2020-10-24 18:38:11 +00:00
|
|
|
|
2020-06-06 12:28:45 +00:00
|
|
|
"github.com/bwmarrin/discordgo"
|
2020-07-19 11:40:53 +00:00
|
|
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
2021-05-06 12:42:37 +00:00
|
|
|
|
2020-07-19 11:40:53 +00:00
|
|
|
"github.com/tribalwarshelp/dcbot/message"
|
2021-07-17 15:22:36 +00:00
|
|
|
"github.com/tribalwarshelp/dcbot/model"
|
|
|
|
"github.com/tribalwarshelp/dcbot/util/twutil"
|
2020-06-06 12:28:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-07-19 11:40:53 +00:00
|
|
|
observationsPerGroup = 10
|
|
|
|
groupsPerServer = 5
|
2020-06-06 12:28:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-07-18 10:21:02 +00:00
|
|
|
cmdAddGroup command = "addgroup"
|
|
|
|
cmdDeleteGroup command = "deletegroup"
|
|
|
|
cmdGroups command = "groups"
|
|
|
|
cmdShowEnnobledBarbarians command = "showennobledbarbs"
|
|
|
|
cmdObserve command = "observe"
|
|
|
|
cmdObservations command = "observations"
|
|
|
|
cmdDeleteObservation command = "deleteobservation"
|
|
|
|
cmdLostVillages command = "lostvillages"
|
|
|
|
cmdDisableLostVillages command = "disablelostvillages"
|
|
|
|
cmdConqueredVillages command = "conqueredvillages"
|
|
|
|
cmdDisableConqueredVillages command = "disableconqueredvillages"
|
|
|
|
cmdShowInternals command = "showinternals"
|
2020-05-30 08:35:45 +00:00
|
|
|
)
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
type hndlrAddGroup struct {
|
2021-07-18 06:48:04 +00:00
|
|
|
*Session
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
var _ commandHandler = &hndlrAddGroup{}
|
2021-07-18 06:48:04 +00:00
|
|
|
|
2021-07-18 10:21:02 +00:00
|
|
|
func (hndlr *hndlrAddGroup) cmd() command {
|
|
|
|
return cmdAddGroup
|
2021-07-18 06:48:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrAddGroup) requireAdmPermissions() bool {
|
2021-07-18 06:48:04 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrAddGroup) execute(ctx *commandCtx, m *discordgo.MessageCreate, args ...string) {
|
2021-07-18 06:48:04 +00:00
|
|
|
if len(ctx.server.Groups) >= groupsPerServer {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.AddGroupLimitHasBeenReached,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
"Total": len(ctx.server.Groups),
|
|
|
|
"Limit": groupsPerServer,
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
group := &model.Group{
|
|
|
|
ServerID: m.GuildID,
|
|
|
|
ShowEnnobledBarbarians: true,
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
if err := hndlr.cfg.GroupRepository.Store(context.Background(), group); err != nil {
|
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.InternalServerError,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.AddGroupSuccess,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
"ID": group.ID,
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
type hndlrDeleteGroup struct {
|
2021-07-18 06:48:04 +00:00
|
|
|
*Session
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
var _ commandHandler = &hndlrDeleteGroup{}
|
2021-07-18 06:48:04 +00:00
|
|
|
|
2021-07-18 10:21:02 +00:00
|
|
|
func (hndlr *hndlrDeleteGroup) cmd() command {
|
|
|
|
return cmdDeleteGroup
|
2021-07-18 06:48:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrDeleteGroup) requireAdmPermissions() bool {
|
2021-07-18 06:48:04 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrDeleteGroup) execute(ctx *commandCtx, m *discordgo.MessageCreate, args ...string) {
|
2021-07-18 06:48:04 +00:00
|
|
|
argsLength := len(args)
|
|
|
|
if argsLength != 1 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpDeleteGroup,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdDeleteGroup.WithPrefix(hndlr.cfg.CommandPrefix),
|
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:48:04 +00:00
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
groupID, err := strconv.Atoi(args[0])
|
|
|
|
if err != nil {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.DeleteGroupInvalidID,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
go hndlr.cfg.GroupRepository.Delete(context.Background(), &model.GroupFilter{
|
2021-07-18 06:48:04 +00:00
|
|
|
ID: []int{groupID},
|
|
|
|
ServerID: []string{m.GuildID},
|
|
|
|
})
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.DeleteGroupSuccess,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
type hndlrGroups struct {
|
2021-07-18 06:48:04 +00:00
|
|
|
*Session
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
var _ commandHandler = &hndlrGroups{}
|
2021-07-18 06:48:04 +00:00
|
|
|
|
2021-07-18 10:21:02 +00:00
|
|
|
func (hndlr *hndlrGroups) cmd() command {
|
|
|
|
return cmdGroups
|
2021-07-18 06:48:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrGroups) requireAdmPermissions() bool {
|
2021-07-18 06:48:04 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrGroups) execute(ctx *commandCtx, m *discordgo.MessageCreate, args ...string) {
|
|
|
|
groups, _, err := hndlr.cfg.GroupRepository.Fetch(context.Background(), &model.GroupFilter{
|
2021-07-18 06:48:04 +00:00
|
|
|
ServerID: []string{m.GuildID},
|
|
|
|
DefaultFilter: model.DefaultFilter{
|
|
|
|
Order: []string{"id ASC"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := ""
|
|
|
|
for i, groups := range groups {
|
|
|
|
msg += fmt.Sprintf("**%d** | %d | %s | %s | %s | %s\n", i+1,
|
|
|
|
groups.ID,
|
|
|
|
boolToEmoji(groups.ConqueredVillagesChannelID != ""),
|
|
|
|
boolToEmoji(groups.LostVillagesChannelID != ""),
|
|
|
|
boolToEmoji(groups.ShowEnnobledBarbarians),
|
|
|
|
boolToEmoji(groups.ShowInternals),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg == "" {
|
|
|
|
msg = ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.GroupsNoGroupsAdded,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendEmbed(m.ChannelID, NewEmbed().
|
2021-07-18 06:48:04 +00:00
|
|
|
SetTitle(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.GroupsTitle,
|
|
|
|
})).
|
|
|
|
AddField(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.GroupsFieldTitle,
|
|
|
|
}), msg))
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
type hndlrConqueredVillages struct {
|
2021-07-18 06:48:04 +00:00
|
|
|
*Session
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
var _ commandHandler = &hndlrConqueredVillages{}
|
2021-07-18 06:48:04 +00:00
|
|
|
|
2021-07-18 10:21:02 +00:00
|
|
|
func (hndlr *hndlrConqueredVillages) cmd() command {
|
|
|
|
return cmdConqueredVillages
|
2021-07-18 06:48:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrConqueredVillages) requireAdmPermissions() bool {
|
2021-07-18 06:48:04 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrConqueredVillages) execute(ctx *commandCtx, m *discordgo.MessageCreate, args ...string) {
|
2021-07-18 06:48:04 +00:00
|
|
|
argsLength := len(args)
|
|
|
|
if argsLength != 1 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpConqueredVillages,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 07:52:13 +00:00
|
|
|
"Command": hndlr.cmd().WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 10:21:02 +00:00
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:48:04 +00:00
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
groupID, err := strconv.Atoi(args[0])
|
|
|
|
if err != nil {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ConqueredVillagesInvalidID,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
groups, _, err := hndlr.cfg.GroupRepository.Fetch(context.Background(), &model.GroupFilter{
|
2021-07-18 06:48:04 +00:00
|
|
|
ID: []int{groupID},
|
|
|
|
ServerID: []string{m.GuildID},
|
|
|
|
})
|
|
|
|
if err != nil || len(groups) == 0 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ConqueredVillagesGroupNotFound,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
groups[0].ConqueredVillagesChannelID = m.ChannelID
|
2021-07-18 07:52:13 +00:00
|
|
|
go hndlr.cfg.GroupRepository.Update(context.Background(), groups[0])
|
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ConqueredVillagesSuccess,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
type hndlrDisableConqueredVillages struct {
|
2021-07-18 06:48:04 +00:00
|
|
|
*Session
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
var _ commandHandler = &hndlrDisableConqueredVillages{}
|
2021-07-18 06:48:04 +00:00
|
|
|
|
2021-07-18 10:21:02 +00:00
|
|
|
func (hndlr *hndlrDisableConqueredVillages) cmd() command {
|
|
|
|
return cmdDisableConqueredVillages
|
2021-07-18 06:48:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrDisableConqueredVillages) requireAdmPermissions() bool {
|
2021-07-18 06:48:04 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrDisableConqueredVillages) execute(ctx *commandCtx, m *discordgo.MessageCreate, args ...string) {
|
2020-06-26 18:30:25 +00:00
|
|
|
argsLength := len(args)
|
2020-10-17 08:27:58 +00:00
|
|
|
if argsLength != 1 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2020-07-19 12:22:41 +00:00
|
|
|
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
2020-10-15 03:37:56 +00:00
|
|
|
MessageID: message.HelpDisableConqueredVillages,
|
2020-07-19 12:22:41 +00:00
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 07:52:13 +00:00
|
|
|
"Command": hndlr.cmd().WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 10:21:02 +00:00
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2020-07-19 12:22:41 +00:00
|
|
|
},
|
|
|
|
}))
|
2020-06-26 18:30:25 +00:00
|
|
|
return
|
2020-06-26 07:47:33 +00:00
|
|
|
}
|
2020-06-26 18:30:25 +00:00
|
|
|
|
|
|
|
groupID, err := strconv.Atoi(args[0])
|
2020-06-26 07:47:33 +00:00
|
|
|
if err != nil {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2020-07-19 12:22:41 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
2020-10-15 03:41:51 +00:00
|
|
|
MessageID: message.DisableConqueredVillagesInvalidID,
|
2020-07-19 12:22:41 +00:00
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
2020-06-26 07:47:33 +00:00
|
|
|
return
|
|
|
|
}
|
2020-06-26 18:30:25 +00:00
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
groups, _, err := hndlr.cfg.GroupRepository.Fetch(context.Background(), &model.GroupFilter{
|
2020-06-26 18:30:25 +00:00
|
|
|
ID: []int{groupID},
|
|
|
|
ServerID: []string{m.GuildID},
|
|
|
|
})
|
|
|
|
if err != nil || len(groups) == 0 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2020-07-19 12:22:41 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
2020-10-15 03:41:51 +00:00
|
|
|
MessageID: message.DisableConqueredVillagesGroupNotFound,
|
2020-07-19 12:22:41 +00:00
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
2020-06-26 18:30:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if groups[0].ConqueredVillagesChannelID != "" {
|
|
|
|
groups[0].ConqueredVillagesChannelID = ""
|
2021-07-18 07:52:13 +00:00
|
|
|
go hndlr.cfg.GroupRepository.Update(context.Background(), groups[0])
|
2020-06-26 07:47:33 +00:00
|
|
|
}
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2020-07-19 12:22:41 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
2020-10-15 03:41:51 +00:00
|
|
|
MessageID: message.DisableConqueredVillagesSuccess,
|
2020-07-19 12:22:41 +00:00
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
2020-06-26 07:47:33 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
type hndlrLostVillages struct {
|
2021-07-18 06:48:04 +00:00
|
|
|
*Session
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
var _ commandHandler = &hndlrLostVillages{}
|
2021-07-18 06:48:04 +00:00
|
|
|
|
2021-07-18 10:21:02 +00:00
|
|
|
func (hndlr *hndlrLostVillages) cmd() command {
|
|
|
|
return cmdLostVillages
|
2021-07-18 06:48:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrLostVillages) requireAdmPermissions() bool {
|
2021-07-18 06:48:04 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrLostVillages) execute(ctx *commandCtx, m *discordgo.MessageCreate, args ...string) {
|
2020-06-26 18:30:25 +00:00
|
|
|
argsLength := len(args)
|
2020-10-17 08:27:58 +00:00
|
|
|
if argsLength != 1 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2020-07-19 12:22:41 +00:00
|
|
|
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
2021-07-18 06:48:04 +00:00
|
|
|
MessageID: message.HelpLostVillages,
|
2020-07-19 12:22:41 +00:00
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 07:52:13 +00:00
|
|
|
"Command": hndlr.cmd().WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 10:21:02 +00:00
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2020-07-19 12:22:41 +00:00
|
|
|
},
|
|
|
|
}))
|
2020-06-26 18:30:25 +00:00
|
|
|
return
|
2020-06-06 12:28:45 +00:00
|
|
|
}
|
2020-06-26 18:30:25 +00:00
|
|
|
|
|
|
|
groupID, err := strconv.Atoi(args[0])
|
2020-06-06 12:28:45 +00:00
|
|
|
if err != nil {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2020-07-19 12:22:41 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
2021-07-18 06:48:04 +00:00
|
|
|
MessageID: message.LostVillagesInvalidID,
|
2020-07-19 12:22:41 +00:00
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
2020-06-26 18:30:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
groups, _, err := hndlr.cfg.GroupRepository.Fetch(context.Background(), &model.GroupFilter{
|
2020-06-26 18:30:25 +00:00
|
|
|
ID: []int{groupID},
|
|
|
|
ServerID: []string{m.GuildID},
|
|
|
|
})
|
|
|
|
if err != nil || len(groups) == 0 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2020-07-19 12:22:41 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
2021-07-18 06:48:04 +00:00
|
|
|
MessageID: message.LostVillagesGroupNotFound,
|
2020-07-19 12:22:41 +00:00
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
2020-06-06 12:28:45 +00:00
|
|
|
return
|
|
|
|
}
|
2020-06-26 18:30:25 +00:00
|
|
|
|
2021-07-18 06:48:04 +00:00
|
|
|
groups[0].LostVillagesChannelID = m.ChannelID
|
2021-07-18 07:52:13 +00:00
|
|
|
go hndlr.cfg.GroupRepository.Update(context.Background(), groups[0])
|
2021-07-18 06:48:04 +00:00
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.LostVillagesSuccess,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
type hndlrDisableLostVillages struct {
|
2021-07-18 06:48:04 +00:00
|
|
|
*Session
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
var _ commandHandler = &hndlrDisableLostVillages{}
|
2021-07-18 06:48:04 +00:00
|
|
|
|
2021-07-18 10:21:02 +00:00
|
|
|
func (hndlr *hndlrDisableLostVillages) cmd() command {
|
|
|
|
return cmdDisableLostVillages
|
2021-07-18 06:48:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrDisableLostVillages) requireAdmPermissions() bool {
|
2021-07-18 06:48:04 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrDisableLostVillages) execute(ctx *commandCtx, m *discordgo.MessageCreate, args ...string) {
|
2021-07-18 06:48:04 +00:00
|
|
|
argsLength := len(args)
|
|
|
|
if argsLength != 1 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpDisableLostVillages,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 07:52:13 +00:00
|
|
|
"Command": hndlr.cmd().WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 10:21:02 +00:00
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:48:04 +00:00
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
groupID, err := strconv.Atoi(args[0])
|
|
|
|
if err != nil {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.DisableLostVillagesInvalidID,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
groups, _, err := hndlr.cfg.GroupRepository.Fetch(context.Background(), &model.GroupFilter{
|
2021-07-18 06:48:04 +00:00
|
|
|
ID: []int{groupID},
|
|
|
|
ServerID: []string{m.GuildID},
|
|
|
|
})
|
|
|
|
if err != nil || len(groups) == 0 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.DisableLostVillagesGroupNotFound,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if groups[0].LostVillagesChannelID != "" {
|
|
|
|
groups[0].LostVillagesChannelID = ""
|
2021-07-18 07:52:13 +00:00
|
|
|
go hndlr.cfg.GroupRepository.Update(context.Background(), groups[0])
|
2021-07-18 06:48:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.DisableLostVillagesSuccess,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
type hndlrObserve struct {
|
2021-07-18 07:14:26 +00:00
|
|
|
*Session
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
var _ commandHandler = &hndlrObserve{}
|
2021-07-18 07:14:26 +00:00
|
|
|
|
2021-07-18 10:21:02 +00:00
|
|
|
func (hndlr *hndlrObserve) cmd() command {
|
|
|
|
return cmdObserve
|
2021-07-18 07:14:26 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrObserve) requireAdmPermissions() bool {
|
2021-07-18 07:14:26 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrObserve) execute(ctx *commandCtx, m *discordgo.MessageCreate, args ...string) {
|
2021-07-18 06:48:04 +00:00
|
|
|
argsLength := len(args)
|
2021-07-18 07:14:26 +00:00
|
|
|
if argsLength != 3 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
2021-07-18 07:14:26 +00:00
|
|
|
MessageID: message.HelpObserve,
|
2021-07-18 06:48:04 +00:00
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 07:52:13 +00:00
|
|
|
"Command": hndlr.cmd().WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 10:21:02 +00:00
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:48:04 +00:00
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
groupID, err := strconv.Atoi(args[0])
|
|
|
|
if err != nil {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
2021-07-18 07:14:26 +00:00
|
|
|
MessageID: message.ObserveInvalidGroupID,
|
2021-07-18 06:48:04 +00:00
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
serverKey := args[1]
|
|
|
|
tribeTag := strings.TrimSpace(args[2])
|
|
|
|
tribeID, err := strconv.Atoi(tribeTag)
|
|
|
|
if (err != nil || tribeID <= 0) && tribeTag == "" {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ObserveInvalidTribeID,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
server, err := hndlr.cfg.API.Server.Read(serverKey, nil)
|
2021-07-18 06:48:04 +00:00
|
|
|
if err != nil || server == nil {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ObserveServerNotFound,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if server.Status == twmodel.ServerStatusClosed {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ObserveServerIsClosed,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var tribe *twmodel.Tribe
|
|
|
|
if tribeID > 0 {
|
2021-07-18 07:52:13 +00:00
|
|
|
tribe, err = hndlr.cfg.API.Tribe.Read(server.Key, tribeID)
|
2021-07-18 06:48:04 +00:00
|
|
|
} else {
|
|
|
|
list := &sdk.TribeList{}
|
2021-07-18 07:52:13 +00:00
|
|
|
list, err = hndlr.cfg.API.Tribe.Browse(server.Key, 1, 0, []string{}, &twmodel.TribeFilter{
|
2021-07-18 06:48:04 +00:00
|
|
|
Tag: []string{tribeTag},
|
|
|
|
})
|
|
|
|
if list != nil && list.Items != nil && len(list.Items) > 0 {
|
|
|
|
tribe = list.Items[0]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err != nil || tribe == nil {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ObserveTribeNotFound,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
group, err := hndlr.cfg.GroupRepository.GetByID(context.Background(), groupID)
|
2021-07-18 06:48:04 +00:00
|
|
|
if err != nil || group.ServerID != m.GuildID {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ObserveGroupNotFound,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(group.Observations) >= observationsPerGroup {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ObserveLimitHasBeenReached,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
"Total": len(group.Observations),
|
|
|
|
"Limit": observationsPerGroup,
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
go hndlr.cfg.ObservationRepository.Store(context.Background(), &model.Observation{
|
2021-07-18 06:48:04 +00:00
|
|
|
Server: server.Key,
|
|
|
|
TribeID: tribe.ID,
|
|
|
|
GroupID: groupID,
|
|
|
|
})
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID, ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
2021-07-18 06:48:04 +00:00
|
|
|
MessageID: message.ObserveSuccess,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
type hndlrDeleteObservation struct {
|
2021-07-18 06:48:04 +00:00
|
|
|
*Session
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
var _ commandHandler = &hndlrDeleteObservation{}
|
2021-07-18 06:48:04 +00:00
|
|
|
|
2021-07-18 10:21:02 +00:00
|
|
|
func (hndlr *hndlrDeleteObservation) cmd() command {
|
|
|
|
return cmdDeleteObservation
|
2021-07-18 06:48:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrDeleteObservation) requireAdmPermissions() bool {
|
2021-07-18 06:48:04 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrDeleteObservation) execute(ctx *commandCtx, m *discordgo.MessageCreate, args ...string) {
|
2021-07-18 06:48:04 +00:00
|
|
|
argsLength := len(args)
|
|
|
|
if argsLength != 2 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpDeleteObservation,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 07:52:13 +00:00
|
|
|
"Command": hndlr.cmd().WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 10:21:02 +00:00
|
|
|
"ObservationsCommand": cmdObservations.WithPrefix(hndlr.cfg.CommandPrefix),
|
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:48:04 +00:00
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
groupID, err := strconv.Atoi(args[0])
|
|
|
|
if err != nil {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.DeleteObservationInvalidGroupID,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
observationID, err := strconv.Atoi(args[1])
|
|
|
|
if err != nil {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.DeleteObservationInvalidTribeID,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
group, err := hndlr.cfg.GroupRepository.GetByID(context.Background(), groupID)
|
2021-07-18 06:48:04 +00:00
|
|
|
if err != nil || group.ServerID != m.GuildID {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.DeleteObservationGroupNotFound,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
go hndlr.cfg.ObservationRepository.Delete(context.Background(), &model.ObservationFilter{
|
2021-07-18 06:48:04 +00:00
|
|
|
GroupID: []int{groupID},
|
|
|
|
ID: []int{observationID},
|
|
|
|
})
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID, ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
2021-07-18 06:48:04 +00:00
|
|
|
MessageID: message.DeleteObservationSuccess,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
type hndlrObservations struct {
|
2021-07-18 06:48:04 +00:00
|
|
|
*Session
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
var _ commandHandler = &hndlrObservations{}
|
2021-07-18 06:48:04 +00:00
|
|
|
|
2021-07-18 10:21:02 +00:00
|
|
|
func (hndlr *hndlrObservations) cmd() command {
|
|
|
|
return cmdObservations
|
2021-07-18 06:48:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrObservations) requireAdmPermissions() bool {
|
2021-07-18 06:48:04 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrObservations) execute(ctx *commandCtx, m *discordgo.MessageCreate, args ...string) {
|
2021-07-18 06:48:04 +00:00
|
|
|
argsLength := len(args)
|
|
|
|
if argsLength != 1 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpObservations,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 07:52:13 +00:00
|
|
|
"Command": hndlr.cmd().WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 10:21:02 +00:00
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:48:04 +00:00
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
groupID, err := strconv.Atoi(args[0])
|
|
|
|
if err != nil {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ObservationsInvalidGroupID,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
2021-07-18 07:52:13 +00:00
|
|
|
group, err := hndlr.cfg.GroupRepository.GetByID(context.Background(), groupID)
|
2021-07-18 06:48:04 +00:00
|
|
|
if err != nil || group.ServerID != m.GuildID {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ObservationsGroupNotFound,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
2021-07-18 07:52:13 +00:00
|
|
|
observations, _, err := hndlr.cfg.ObservationRepository.Fetch(context.Background(), &model.ObservationFilter{
|
2021-07-18 06:48:04 +00:00
|
|
|
GroupID: []int{groupID},
|
|
|
|
DefaultFilter: model.DefaultFilter{
|
|
|
|
Order: []string{"id ASC"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.InternalServerError,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
tribeIDsByServer := make(map[string][]int)
|
|
|
|
var versionCodes []twmodel.VersionCode
|
|
|
|
for _, observation := range observations {
|
|
|
|
tribeIDsByServer[observation.Server] = append(tribeIDsByServer[observation.Server], observation.TribeID)
|
|
|
|
currentCode := twmodel.VersionCodeFromServerKey(observation.Server)
|
|
|
|
unique := true
|
|
|
|
for _, code := range versionCodes {
|
|
|
|
if code == currentCode {
|
|
|
|
unique = false
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if unique {
|
|
|
|
versionCodes = append(versionCodes, currentCode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for server, tribeIDs := range tribeIDsByServer {
|
2021-07-18 07:52:13 +00:00
|
|
|
list, err := hndlr.cfg.API.Tribe.Browse(server, 0, 0, []string{}, &twmodel.TribeFilter{
|
2021-07-18 06:48:04 +00:00
|
|
|
ID: tribeIDs,
|
|
|
|
})
|
|
|
|
if err != nil {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.InternalServerError,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, tribe := range list.Items {
|
|
|
|
for _, observation := range observations {
|
|
|
|
if observation.TribeID == tribe.ID && observation.Server == server {
|
|
|
|
observation.Tribe = tribe
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-18 07:52:13 +00:00
|
|
|
versionList, err := hndlr.cfg.API.Version.Browse(0, 0, []string{}, &twmodel.VersionFilter{
|
2021-07-18 06:48:04 +00:00
|
|
|
Code: versionCodes,
|
2020-06-06 12:28:45 +00:00
|
|
|
})
|
|
|
|
|
2021-07-18 06:48:04 +00:00
|
|
|
bldr := &MessageEmbedFieldBuilder{}
|
|
|
|
if len(observations) <= 0 || err != nil || versionList == nil || versionList.Items == nil {
|
|
|
|
bldr.Append("-")
|
|
|
|
} else {
|
|
|
|
for i, observation := range observations {
|
|
|
|
tag := "Unknown"
|
|
|
|
if observation.Tribe != nil {
|
|
|
|
tag = observation.Tribe.Tag
|
|
|
|
}
|
|
|
|
version := twutil.FindVersionByCode(versionList.Items, twmodel.VersionCodeFromServerKey(observation.Server))
|
|
|
|
tribeURL := ""
|
|
|
|
if version != nil {
|
|
|
|
tribeURL = twurlbuilder.BuildTribeURL(observation.Server, version.Host, observation.TribeID)
|
|
|
|
}
|
|
|
|
bldr.Append(fmt.Sprintf("**%d** | %d - %s - %s\n", i+1, observation.ID,
|
|
|
|
observation.Server,
|
|
|
|
BuildLink(tag, tribeURL)))
|
|
|
|
}
|
|
|
|
}
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendEmbed(m.ChannelID, NewEmbed().
|
2021-07-18 08:17:45 +00:00
|
|
|
SetTitle(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ObservationsTitle,
|
|
|
|
})).
|
2021-07-18 06:48:04 +00:00
|
|
|
SetFields(bldr.ToMessageEmbedFields()))
|
2020-06-06 12:28:45 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
type hndlrShowEnnobledBarbarians struct {
|
2021-07-18 06:48:04 +00:00
|
|
|
*Session
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
var _ commandHandler = &hndlrShowEnnobledBarbarians{}
|
2021-07-18 06:48:04 +00:00
|
|
|
|
2021-07-18 10:21:02 +00:00
|
|
|
func (hndlr *hndlrShowEnnobledBarbarians) cmd() command {
|
|
|
|
return cmdShowEnnobledBarbarians
|
2021-07-18 06:48:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrShowEnnobledBarbarians) requireAdmPermissions() bool {
|
2021-07-18 06:48:04 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrShowEnnobledBarbarians) execute(ctx *commandCtx, m *discordgo.MessageCreate, args ...string) {
|
2021-07-18 06:48:04 +00:00
|
|
|
argsLength := len(args)
|
|
|
|
if argsLength != 1 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpShowEnnobledBarbs,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 10:21:02 +00:00
|
|
|
"Command": cmdShowEnnobledBarbarians.WithPrefix(hndlr.cfg.CommandPrefix),
|
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:48:04 +00:00
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
groupID, err := strconv.Atoi(args[0])
|
|
|
|
if err != nil || groupID <= 0 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ShowEnnobledBarbsInvalidGroupID,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
2021-07-18 07:52:13 +00:00
|
|
|
group, err := hndlr.cfg.GroupRepository.GetByID(context.Background(), groupID)
|
2021-07-18 06:48:04 +00:00
|
|
|
if err != nil || group.ServerID != m.GuildID {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ShowEnnobledBarbsGroupNotFound,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
oldValue := group.ShowEnnobledBarbarians
|
|
|
|
group.ShowEnnobledBarbarians = !oldValue
|
2021-07-18 07:52:13 +00:00
|
|
|
if err := hndlr.cfg.GroupRepository.Update(context.Background(), group); err != nil {
|
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.InternalServerError,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if oldValue {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ShowEnnobledBarbsSuccess1,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ShowEnnobledBarbsSuccess2,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
type hndlrShowInternals struct {
|
2021-07-18 06:48:04 +00:00
|
|
|
*Session
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
var _ commandHandler = &hndlrShowInternals{}
|
2021-07-18 06:48:04 +00:00
|
|
|
|
2021-07-18 10:21:02 +00:00
|
|
|
func (hndlr *hndlrShowInternals) cmd() command {
|
|
|
|
return cmdShowInternals
|
2021-07-18 06:48:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrShowInternals) requireAdmPermissions() bool {
|
2021-07-18 06:48:04 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-07-18 07:52:13 +00:00
|
|
|
func (hndlr *hndlrShowInternals) execute(ctx *commandCtx, m *discordgo.MessageCreate, args ...string) {
|
2021-07-18 06:48:04 +00:00
|
|
|
argsLength := len(args)
|
|
|
|
if argsLength != 1 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
m.Author.Mention()+" "+ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.HelpShowInternals,
|
|
|
|
TemplateData: map[string]interface{}{
|
2021-07-18 07:52:13 +00:00
|
|
|
"Command": hndlr.cmd().WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 10:21:02 +00:00
|
|
|
"GroupsCommand": cmdGroups.WithPrefix(hndlr.cfg.CommandPrefix),
|
2021-07-18 06:48:04 +00:00
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
groupID, err := strconv.Atoi(args[0])
|
|
|
|
if err != nil || groupID <= 0 {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ShowInternalsInvalidGroupID,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
2021-07-18 07:52:13 +00:00
|
|
|
group, err := hndlr.cfg.GroupRepository.GetByID(context.Background(), groupID)
|
2021-07-18 06:48:04 +00:00
|
|
|
if err != nil || group.ServerID != m.GuildID {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ShowInternalsGroupNotFound,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
oldValue := group.ShowInternals
|
|
|
|
group.ShowInternals = !oldValue
|
2021-07-18 07:52:13 +00:00
|
|
|
if err := hndlr.cfg.GroupRepository.Update(context.Background(), group); err != nil {
|
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.InternalServerError,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if oldValue {
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ShowInternalsSuccess1,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
return
|
|
|
|
}
|
2021-07-18 07:52:13 +00:00
|
|
|
hndlr.SendMessage(m.ChannelID,
|
2021-07-18 06:48:04 +00:00
|
|
|
ctx.localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
|
|
MessageID: message.ShowInternalsSuccess2,
|
|
|
|
TemplateData: map[string]interface{}{
|
|
|
|
"Mention": m.Author.Mention(),
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|