humanify: Move constant string out of code

master
Luther Wen Xu 2020-05-11 14:43:55 +07:00
parent 41c8173c95
commit 1828615e94
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
4 changed files with 49 additions and 4 deletions

@ -6,6 +6,7 @@ import (
"github.com/bwmarrin/discordgo"
"gitea.teamortix.com/chanbakjsd/Milen/db"
"gitea.teamortix.com/chanbakjsd/Milen/humanify"
"gitea.teamortix.com/chanbakjsd/Milen/util"
)
@ -18,12 +19,12 @@ func Event(dg *discordgo.Session, m *discordgo.MessageCreate) {
case "autorole":
util.RequireAdmin(dg, m.Author.ID, m.ChannelID, func() {
if len(split) < 6 {
util.SendCheckError(dg, m.ChannelID, "❌ Incorrect usage. Usage: `milen autorole <role> <channel> <message> <emoji>`")
util.SendCheckError(dg, m.ChannelID, humanify.Eng.Usage.Autorole)
return
}
role := util.ParseRole(split[2])
if role == "" {
util.SendCheckError(dg, m.ChannelID, "❌ Incorrect usage. Usage: `milen autorole <role> <channel> <message> <emoji>`")
util.SendCheckError(dg, m.ChannelID, humanify.Eng.Usage.Autorole)
return
}
emoji := util.ParseEmoji(split[5])
@ -33,7 +34,7 @@ func Event(dg *discordgo.Session, m *discordgo.MessageCreate) {
util.ReportError(dg, err)
return
}
util.SendCheckError(dg, m.ChannelID, "✅ Auto-role registered.")
util.SendCheckError(dg, m.ChannelID, humanify.Eng.Autorole.Success)
})
}
}

@ -0,0 +1,35 @@
package humanify
import (
"fmt"
"io/ioutil"
"github.com/BurntSushi/toml"
)
var Eng Locale
type Locale struct {
NoAdmin string `toml:"no_admin"`
Usage localeUsage
Autorole localeAutorole
}
type localeUsage struct {
Autorole string `toml:"autorole"`
}
type localeAutorole struct {
Success string `toml:"success"`
}
func init() {
data, err := ioutil.ReadFile("locale.toml")
if err != nil {
panic(err)
}
err = toml.Unmarshal(data, &Eng)
if err != nil {
panic(err)
}
}

@ -0,0 +1,7 @@
no_admin="❌ You do not have permission to use this command."
[usage]
autorole="❌ Incorrect usage. Usage: `milen autorole <role> <channel> <message> <emoji>`"
[autorole]
success="✅ Auto-role registered."

@ -2,6 +2,8 @@ package util
import (
"github.com/bwmarrin/discordgo"
"gitea.teamortix.com/chanbakjsd/Milen/humanify"
)
func RequireAdmin(dg *discordgo.Session, userID string, channelID string, hasAdmin func()) {
@ -11,7 +13,7 @@ func RequireAdmin(dg *discordgo.Session, userID string, channelID string, hasAdm
return
}
if perm&discordgo.PermissionAdministrator == 0 {
SendCheckError(dg, channelID, "❌ You do not have permission to use this command.")
SendCheckError(dg, channelID, humanify.Eng.NoAdmin)
return
}
hasAdmin()