commands.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "log"
  6. "os"
  7. "path/filepath"
  8. "runtime"
  9. "strings"
  10. "time"
  11. "github.com/Necroforger/dgrouter/exrouter"
  12. "github.com/bwmarrin/discordgo"
  13. "github.com/fatih/color"
  14. "github.com/hako/durafmt"
  15. "github.com/kennygrant/sanitize"
  16. )
  17. // Multiple use messages to save space and make cleaner.
  18. // TODO: Implement this for more?
  19. const (
  20. cmderrLackingBotAdminPerms = "You do not have permission to use this command. Your User ID must be set as a bot administrator in the settings file."
  21. cmderrSendFailure = "Failed to send command message (requested by %s)...\t%s"
  22. )
  23. func handleCommands() *exrouter.Route {
  24. router := exrouter.New()
  25. //#region Utility Commands
  26. go router.On("ping", func(ctx *exrouter.Context) {
  27. if isCommandableChannel(ctx.Msg) {
  28. if !hasPerms(ctx.Msg.ChannelID, discordgo.PermissionSendMessages) {
  29. log.Println(lg("Command", "Ping", color.HiRedString, fmtBotSendPerm, ctx.Msg.ChannelID))
  30. } else {
  31. beforePong := time.Now()
  32. pong, err := ctx.Reply("Pong!")
  33. if err != nil {
  34. log.Println(lg("Command", "Ping", color.HiRedString, "Error sending pong message:\t%s", err))
  35. } else {
  36. afterPong := time.Now()
  37. latency := bot.HeartbeatLatency().Milliseconds()
  38. roundtrip := afterPong.Sub(beforePong).Milliseconds()
  39. mention := ctx.Msg.Author.Mention()
  40. content := fmt.Sprintf("**Latency:** ``%dms`` — **Roundtrip:** ``%dms``",
  41. latency,
  42. roundtrip,
  43. )
  44. if pong != nil {
  45. if selfbot {
  46. bot.ChannelMessageEdit(pong.ChannelID, pong.ID, fmt.Sprintf("%s **Command — Ping**\n\n%s", mention, content))
  47. } else {
  48. bot.ChannelMessageEditComplex(&discordgo.MessageEdit{
  49. ID: pong.ID,
  50. Channel: pong.ChannelID,
  51. Content: &mention,
  52. Embed: buildEmbed(ctx.Msg.ChannelID, "Command — Ping", content),
  53. })
  54. }
  55. }
  56. // Log
  57. log.Println(lg("Command", "Ping", color.HiCyanString, "%s pinged bot - Latency: %dms, Roundtrip: %dms",
  58. getUserIdentifier(*ctx.Msg.Author),
  59. latency,
  60. roundtrip),
  61. )
  62. }
  63. }
  64. }
  65. }).Cat("Utility").Alias("test").Desc("Pings the bot")
  66. go router.On("help", func(ctx *exrouter.Context) {
  67. if isCommandableChannel(ctx.Msg) {
  68. if !hasPerms(ctx.Msg.ChannelID, discordgo.PermissionSendMessages) {
  69. log.Println(lg("Command", "Help", color.HiRedString, fmtBotSendPerm, ctx.Msg.ChannelID))
  70. } else {
  71. content := ""
  72. for _, cmd := range router.Routes {
  73. if cmd.Category != "Admin" || isBotAdmin(ctx.Msg) {
  74. content += fmt.Sprintf("• \"%s\" : %s",
  75. cmd.Name,
  76. cmd.Description,
  77. )
  78. if len(cmd.Aliases) > 0 {
  79. content += fmt.Sprintf("\n— Aliases: \"%s\"", strings.Join(cmd.Aliases, "\", \""))
  80. }
  81. content += "\n\n"
  82. }
  83. }
  84. if _, err := replyEmbed(ctx.Msg, "Command — Help",
  85. fmt.Sprintf("Use commands as ``\"%s<command> <arguments?>\"``\n```%s```\n%s",
  86. config.CommandPrefix, content, projectRepoURL)); err != nil {
  87. log.Println(lg("Command", "Help", color.HiRedString, cmderrSendFailure, getUserIdentifier(*ctx.Msg.Author), err))
  88. }
  89. log.Println(lg("Command", "Help", color.HiCyanString, "%s asked for help", getUserIdentifier(*ctx.Msg.Author)))
  90. }
  91. }
  92. }).Cat("Utility").Alias("commands").Desc("Outputs this help menu")
  93. //#endregion
  94. //#region Info Commands
  95. go router.On("status", func(ctx *exrouter.Context) {
  96. if isCommandableChannel(ctx.Msg) {
  97. if !hasPerms(ctx.Msg.ChannelID, discordgo.PermissionSendMessages) {
  98. log.Println(lg("Command", "Status", color.HiRedString, fmtBotSendPerm, ctx.Msg.ChannelID))
  99. } else {
  100. message := fmt.Sprintf("• **Uptime —** %s\n"+
  101. "• **Started at —** %s\n"+
  102. "• **Joined Servers —** %d\n"+
  103. "• **Bound Channels —** %d\n"+
  104. "• **Bound Servers —** %d\n"+
  105. "• **Admin Channels —** %d\n"+
  106. "• **Heartbeat Latency —** %dms",
  107. durafmt.Parse(time.Since(startTime)).String(),
  108. startTime.Format("03:04:05pm on Monday, January 2, 2006 (MST)"),
  109. len(bot.State.Guilds),
  110. getBoundChannelsCount(),
  111. getBoundServersCount(),
  112. len(config.AdminChannels),
  113. bot.HeartbeatLatency().Milliseconds(),
  114. )
  115. if sourceConfig := getSource(ctx.Msg); sourceConfig != emptyConfig {
  116. configJson, _ := json.MarshalIndent(sourceConfig, "", "\t")
  117. message = message + fmt.Sprintf("\n• **Channel Settings...** ```%s```", string(configJson))
  118. }
  119. if _, err := replyEmbed(ctx.Msg, "Command — Status", message); err != nil {
  120. log.Println(lg("Command", "Status", color.HiRedString, cmderrSendFailure, getUserIdentifier(*ctx.Msg.Author), err))
  121. }
  122. log.Println(lg("Command", "Status", color.HiCyanString, "%s requested status report", getUserIdentifier(*ctx.Msg.Author)))
  123. }
  124. }
  125. }).Cat("Info").Desc("Displays info regarding the current status of the bot")
  126. go router.On("stats", func(ctx *exrouter.Context) {
  127. if isCommandableChannel(ctx.Msg) {
  128. if !hasPerms(ctx.Msg.ChannelID, discordgo.PermissionSendMessages) {
  129. log.Println(lg("Command", "Stats", color.HiRedString, fmtBotSendPerm, ctx.Msg.ChannelID))
  130. } else {
  131. if sourceConfig := getSource(ctx.Msg); sourceConfig != emptyConfig {
  132. if *sourceConfig.AllowCommands {
  133. content := fmt.Sprintf("• **Total Downloads —** %s\n"+
  134. "• **Downloads in this Channel —** %s",
  135. formatNumber(int64(dbDownloadCount())),
  136. formatNumber(int64(dbDownloadCountByChannel(ctx.Msg.ChannelID))),
  137. )
  138. //TODO: Count in channel by users
  139. if _, err := replyEmbed(ctx.Msg, "Command — Stats", content); err != nil {
  140. log.Println(lg("Command", "Stats", color.HiRedString, cmderrSendFailure,
  141. getUserIdentifier(*ctx.Msg.Author), err))
  142. }
  143. log.Println(lg("Command", "Stats", color.HiCyanString, "%s requested stats",
  144. getUserIdentifier(*ctx.Msg.Author)))
  145. }
  146. }
  147. }
  148. }
  149. }).Cat("Info").Desc("Outputs statistics regarding this channel")
  150. go router.On("info", func(ctx *exrouter.Context) {
  151. if isCommandableChannel(ctx.Msg) {
  152. if !hasPerms(ctx.Msg.ChannelID, discordgo.PermissionSendMessages) {
  153. log.Println(lg("Command", "Info", color.HiRedString, fmtBotSendPerm, ctx.Msg.ChannelID))
  154. } else {
  155. content := fmt.Sprintf("Here is some useful info...\n\n"+
  156. "• **Your User ID —** `%s`\n"+
  157. "• **Bots User ID —** `%s`\n"+
  158. "• **This Channel ID —** `%s`\n"+
  159. "• **This Server ID —** `%s`\n\n"+
  160. "• **Versions —`%s, discordgo v%s (modified), Discord API v%s`"+
  161. "\n\nRemember to remove any spaces when copying to settings.",
  162. ctx.Msg.Author.ID, botUser.ID, ctx.Msg.ChannelID, ctx.Msg.GuildID, runtime.Version(), discordgo.VERSION, discordgo.APIVersion)
  163. if _, err := replyEmbed(ctx.Msg, "Command — Info", content); err != nil {
  164. log.Println(lg("Command", "Info", color.HiRedString, cmderrSendFailure, getUserIdentifier(*ctx.Msg.Author), err))
  165. }
  166. log.Println(lg("Command", "Info", color.HiCyanString, "%s requested info", getUserIdentifier(*ctx.Msg.Author)))
  167. }
  168. }
  169. }).Cat("Info").Alias("debug").Desc("Displays info regarding Discord IDs")
  170. //#endregion
  171. //#region Admin Commands
  172. go router.On("history", func(ctx *exrouter.Context) {
  173. if isCommandableChannel(ctx.Msg) {
  174. // Vars
  175. var channels []string
  176. var shouldAbort bool = false
  177. var shouldProcess bool = true
  178. var before string
  179. var beforeID string
  180. var since string
  181. var sinceID string
  182. //#region Parse Args
  183. for argKey, argValue := range ctx.Args {
  184. if argKey == 0 { // skip head
  185. continue
  186. }
  187. if strings.Contains(strings.ToLower(argValue), "cancel") ||
  188. strings.Contains(strings.ToLower(argValue), "stop") {
  189. shouldAbort = true
  190. } else if strings.Contains(strings.ToLower(argValue), "help") ||
  191. strings.Contains(strings.ToLower(argValue), "info") {
  192. shouldProcess = false
  193. if hasPerms(ctx.Msg.ChannelID, discordgo.PermissionSendMessages) {
  194. //content := fmt.Sprintf("")
  195. _, err := replyEmbed(ctx.Msg, "Command — History Help", "TODO: this")
  196. if err != nil {
  197. log.Println(lg("Command", "History",
  198. color.HiRedString, cmderrSendFailure, getUserIdentifier(*ctx.Msg.Author), err))
  199. }
  200. } else {
  201. log.Println(lg("Command", "History", color.HiRedString, fmtBotSendPerm, ctx.Msg.ChannelID))
  202. }
  203. log.Println(lg("Command", "History", color.CyanString, "%s requested history help.", getUserIdentifier(*ctx.Msg.Author)))
  204. } else if strings.Contains(strings.ToLower(argValue), "list") ||
  205. strings.Contains(strings.ToLower(argValue), "status") ||
  206. strings.Contains(strings.ToLower(argValue), "output") {
  207. shouldProcess = false
  208. output := "Running history jobs...\n"
  209. for channelID, job := range historyJobs {
  210. channelLabel := channelID
  211. channelInfo, err := bot.State.Channel(channelID)
  212. if err == nil {
  213. channelLabel = "#" + channelInfo.Name
  214. }
  215. output += fmt.Sprintf("• _%s_ - (%s)`%s`, `updated %s ago, added %s ago`\n",
  216. historyStatusLabel(job.Status), job.OriginUser, channelLabel,
  217. durafmt.ParseShort(time.Since(job.Updated)).String(), durafmt.ParseShort(time.Since(job.Added)).String())
  218. log.Println(lg("Command", "History", color.HiCyanString, "History Job: %s - (%s)%s, updated %s ago, added %s ago",
  219. historyStatusLabel(job.Status), job.OriginUser, channelLabel,
  220. durafmt.ParseShort(time.Since(job.Updated)).String(), durafmt.ParseShort(time.Since(job.Added)).String()))
  221. }
  222. if hasPerms(ctx.Msg.ChannelID, discordgo.PermissionSendMessages) {
  223. _, err := ctx.Reply(output)
  224. if err != nil {
  225. log.Println(lg("Command", "History", color.HiRedString, cmderrSendFailure, getUserIdentifier(*ctx.Msg.Author), err))
  226. }
  227. } else {
  228. log.Println(lg("Command", "History", color.HiRedString, fmtBotSendPerm, ctx.Msg.ChannelID))
  229. }
  230. log.Println(lg("Command", "History", color.HiRedString, "%s requested statuses of history jobs.",
  231. getUserIdentifier(*ctx.Msg.Author)))
  232. } else if strings.Contains(strings.ToLower(argValue), "--before=") { // before key
  233. before = strings.ReplaceAll(strings.ToLower(argValue), "--before=", "")
  234. if isDate(before) {
  235. beforeID = discordTimestampToSnowflake("2006-01-02", dateLocalToUTC(before))
  236. } else if isNumeric(before) {
  237. beforeID = before
  238. }
  239. if config.DebugOutput {
  240. log.Println(lg("Command", "History", color.CyanString, "Date range applied, before %s", beforeID))
  241. }
  242. } else if strings.Contains(strings.ToLower(argValue), "--since=") { // since key
  243. since = strings.ReplaceAll(strings.ToLower(argValue), "--since=", "")
  244. if isDate(since) {
  245. sinceID = discordTimestampToSnowflake("2006-01-02", dateLocalToUTC(since))
  246. } else if isNumeric(since) {
  247. sinceID = since
  248. }
  249. if config.DebugOutput {
  250. log.Println(lg("Command", "History", color.CyanString, "Date range applied, since %s", sinceID))
  251. }
  252. } else {
  253. // Actual Source ID(s)
  254. targets := strings.Split(ctx.Args.Get(argKey), ",")
  255. for _, target := range targets {
  256. if isNumeric(target) {
  257. // Test/Use if number is guild
  258. guild, err := bot.State.Guild(target)
  259. if err == nil {
  260. if config.DebugOutput {
  261. log.Println(lg("Command", "History", color.YellowString,
  262. "Specified target %s is a guild: \"%s\", adding all channels...",
  263. target, guild.Name))
  264. }
  265. for _, ch := range guild.Channels {
  266. channels = append(channels, ch.ID)
  267. if config.DebugOutput {
  268. log.Println(lg("Command", "History", color.YellowString,
  269. "Added %s (#%s in \"%s\") to history queue",
  270. ch.ID, ch.Name, guild.Name))
  271. }
  272. }
  273. } else { // Test/Use if number is channel
  274. ch, err := bot.State.Channel(target)
  275. if err == nil {
  276. channels = append(channels, target)
  277. if config.DebugOutput {
  278. log.Println(lg("Command", "History", color.YellowString, "Added %s (#%s in %s) to history queue",
  279. ch.ID, ch.Name, ch.GuildID))
  280. }
  281. }
  282. }
  283. } else if strings.Contains(strings.ToLower(target), "all") {
  284. channels = getAllRegisteredChannels()
  285. }
  286. }
  287. }
  288. }
  289. //#endregion
  290. //#region Process Channels
  291. if shouldProcess {
  292. // Local
  293. if len(channels) == 0 {
  294. channels = append(channels, ctx.Msg.ChannelID)
  295. }
  296. // Foreach Channel
  297. for _, channel := range channels {
  298. if config.DebugOutput {
  299. label := channel
  300. if chinfo, err := bot.State.Channel(channel); err == nil {
  301. label = chinfo.GuildID + "#" + chinfo.Name
  302. }
  303. log.Println(lg("Command", "History", color.GreenString,
  304. "Queueing history job for %s...", label))
  305. }
  306. if !isBotAdmin(ctx.Msg) {
  307. log.Println(lg("Command", "History", color.CyanString,
  308. "%s tried to cache history for %s but lacked proper permission.",
  309. getUserIdentifier(*ctx.Msg.Author), channel))
  310. if !hasPerms(ctx.Msg.ChannelID, discordgo.PermissionSendMessages) {
  311. log.Println(lg("Command", "History", color.HiRedString, fmtBotSendPerm, channel))
  312. } else {
  313. if _, err := replyEmbed(ctx.Msg, "Command — History", cmderrLackingBotAdminPerms); err != nil {
  314. log.Println(lg("Command", "History", color.HiRedString, cmderrSendFailure,
  315. getUserIdentifier(*ctx.Msg.Author), err))
  316. }
  317. }
  318. } else {
  319. // Run
  320. if !shouldAbort {
  321. if job, exists := historyJobs[channel]; !exists ||
  322. (job.Status != historyStatusDownloading && job.Status != historyStatusAbortRequested) {
  323. job.Status = historyStatusWaiting
  324. job.OriginChannel = ctx.Msg.ChannelID
  325. job.OriginUser = getUserIdentifier(*ctx.Msg.Author)
  326. job.TargetCommandingMessage = ctx.Msg
  327. job.TargetChannelID = channel
  328. job.TargetBefore = beforeID
  329. job.TargetSince = sinceID
  330. job.Updated = time.Now()
  331. job.Added = time.Now()
  332. historyJobs[channel] = job
  333. } else { // ALREADY RUNNING
  334. log.Println(lg("Command", "History", color.CyanString,
  335. "%s tried using history command but history is already running for %s...",
  336. getUserIdentifier(*ctx.Msg.Author), channel))
  337. }
  338. } else if historyJobs[channel].Status == historyStatusDownloading ||
  339. historyJobs[channel].Status == historyStatusWaiting { // requested abort while downloading
  340. if job, exists := historyJobs[channel]; exists {
  341. job.Status = historyStatusAbortRequested
  342. if historyJobs[channel].Status == historyStatusWaiting {
  343. job.Status = historyStatusAbortCompleted
  344. }
  345. historyJobs[channel] = job
  346. }
  347. log.Println(lg("Command", "History", color.CyanString,
  348. "%s cancelled history cataloging for \"%s\"",
  349. getUserIdentifier(*ctx.Msg.Author), channel))
  350. } else { // tried to stop but is not downloading
  351. log.Println(lg("Command", "History", color.CyanString,
  352. "%s tried to cancel history for \"%s\" but it's not running",
  353. getUserIdentifier(*ctx.Msg.Author), channel))
  354. }
  355. }
  356. }
  357. }
  358. //#endregion
  359. }
  360. }).Cat("Admin").Alias("catalog", "cache").Desc("Catalogs history for this channel")
  361. go router.On("exit", func(ctx *exrouter.Context) {
  362. if isCommandableChannel(ctx.Msg) {
  363. if isBotAdmin(ctx.Msg) {
  364. if !hasPerms(ctx.Msg.ChannelID, discordgo.PermissionSendMessages) {
  365. log.Println(lg("Command", "Exit", color.HiRedString, fmtBotSendPerm, ctx.Msg.ChannelID))
  366. } else {
  367. if _, err := replyEmbed(ctx.Msg, "Command — Exit", "Exiting program..."); err != nil {
  368. log.Println(lg("Command", "Exit", color.HiRedString,
  369. cmderrSendFailure, getUserIdentifier(*ctx.Msg.Author), err))
  370. }
  371. }
  372. log.Println(lg("Command", "Exit", color.HiCyanString,
  373. "%s (bot admin) requested exit, goodbye...",
  374. getUserIdentifier(*ctx.Msg.Author)))
  375. properExit()
  376. } else {
  377. if !hasPerms(ctx.Msg.ChannelID, discordgo.PermissionSendMessages) {
  378. log.Println(lg("Command", "Exit", color.HiRedString, fmtBotSendPerm, ctx.Msg.ChannelID))
  379. } else {
  380. if _, err := replyEmbed(ctx.Msg, "Command — Exit", cmderrLackingBotAdminPerms); err != nil {
  381. log.Println(lg("Command", "Exit", color.HiRedString,
  382. cmderrSendFailure, getUserIdentifier(*ctx.Msg.Author), err))
  383. }
  384. }
  385. log.Println(lg("Command", "Exit", color.HiCyanString,
  386. "%s tried to exit but lacked bot admin perms.", getUserIdentifier(*ctx.Msg.Author)))
  387. }
  388. }
  389. }).Cat("Admin").Alias("reload", "kill").Desc("Kills the bot")
  390. go router.On("emojis", func(ctx *exrouter.Context) {
  391. if isCommandableChannel(ctx.Msg) {
  392. if isBotAdmin(ctx.Msg) {
  393. if hasPerms(ctx.Msg.ChannelID, discordgo.PermissionSendMessages) {
  394. // Determine which guild(s)
  395. guilds := []string{ctx.Msg.GuildID} // default to origin
  396. if args := ctx.Args.After(1); args != "" { // specifics
  397. guilds = nil
  398. _guilds := strings.Split(args, ",")
  399. if len(_guilds) > 0 {
  400. for _, guild := range _guilds {
  401. guild = strings.TrimSpace(guild)
  402. guilds = append(guilds, guild)
  403. }
  404. }
  405. }
  406. for _, guild := range guilds {
  407. i := 0
  408. s := 0
  409. guildName := guild
  410. guildNameO := guild
  411. if guildInfo, err := bot.Guild(guild); err == nil {
  412. guildName = sanitize.Name(guildInfo.Name)
  413. guildNameO = guildInfo.Name
  414. }
  415. destination := "emojis" + string(os.PathSeparator) + guildName + string(os.PathSeparator)
  416. if err = os.MkdirAll(destination, 0755); err != nil {
  417. log.Println(lg("Command", "Emojis", color.HiRedString, "Error while creating destination folder \"%s\": %s", destination, err))
  418. } else {
  419. emojis, err := bot.GuildEmojis(guild)
  420. if err != nil {
  421. log.Println(lg("Command", "Emojis", color.HiRedString, "Failed to get server emojis:\t%s", err))
  422. } else {
  423. for _, emoji := range emojis {
  424. var message discordgo.Message
  425. message.ChannelID = ctx.Msg.ChannelID
  426. url := "https://cdn.discordapp.com/emojis/" + emoji.ID
  427. status := handleDownload(
  428. downloadRequestStruct{
  429. InputURL: url,
  430. Filename: emoji.ID,
  431. Path: destination,
  432. Message: &message,
  433. FileTime: time.Now(),
  434. HistoryCmd: false,
  435. EmojiCmd: true,
  436. StartTime: time.Now(),
  437. })
  438. if status.Status == downloadSuccess {
  439. i++
  440. } else {
  441. s++
  442. log.Println(lg("Command", "Emojis", color.HiRedString,
  443. "Failed to download emoji \"%s\": \t[%d - %s] %v",
  444. url, status.Status, getDownloadStatusString(status.Status), status.Error))
  445. }
  446. }
  447. destinationOut := destination
  448. abs, err := filepath.Abs(destination)
  449. if err == nil {
  450. destinationOut = abs
  451. }
  452. _, err = replyEmbed(ctx.Msg, "Command — Emojis",
  453. fmt.Sprintf("`%d` emojis downloaded, `%d` skipped or failed\n• Destination: `%s`\n• Server: `%s`",
  454. i, s, destinationOut, guildNameO,
  455. ),
  456. )
  457. if err != nil {
  458. log.Println(lg("Command", "Emojis", color.HiRedString,
  459. "Failed to send status message for emoji downloads:\t%s", err))
  460. }
  461. }
  462. }
  463. }
  464. }
  465. } else {
  466. if !hasPerms(ctx.Msg.ChannelID, discordgo.PermissionSendMessages) {
  467. log.Println(lg("Command", "Emojis", color.HiRedString, fmtBotSendPerm, ctx.Msg.ChannelID))
  468. } else {
  469. if _, err := replyEmbed(ctx.Msg, "Command — Emojis", cmderrLackingBotAdminPerms); err != nil {
  470. log.Println(lg("Command", "Emojis", color.HiRedString, cmderrSendFailure, getUserIdentifier(*ctx.Msg.Author), err))
  471. }
  472. }
  473. log.Println(lg("Command", "Emojis", color.HiCyanString,
  474. "%s tried to download emojis but lacked bot admin perms.", getUserIdentifier(*ctx.Msg.Author)))
  475. }
  476. }
  477. }).Cat("Admin").Desc("Saves all server emojis to download destination")
  478. //#endregion
  479. // Handler for Command Router
  480. go bot.AddHandler(func(_ *discordgo.Session, m *discordgo.MessageCreate) {
  481. //NOTE: This setup makes it case-insensitive but message content will be lowercase, currently case sensitivity is not necessary.
  482. router.FindAndExecute(bot, strings.ToLower(config.CommandPrefix), bot.State.User.ID, messageToLower(m.Message))
  483. })
  484. return router
  485. }