Browse Source

bound cat and user

Drn 2 years ago
parent
commit
4b67e2f585
5 changed files with 83 additions and 4 deletions
  1. 2 0
      README.md
  2. 4 0
      commands.go
  3. 48 0
      config.go
  4. 14 2
      discord.go
  5. 15 2
      main.go

+ 2 - 0
README.md

@@ -1064,7 +1064,9 @@ Key | Description
 `{{count}}`                 | Raw total count of downloads
 `{{countShort}}`            | Shortened total count of downloads
 `{{numServers}}`            | Number of servers bot is in
+`{{numBoundUsers}}`         | Number of bound users
 `{{numBoundServers}}`       | Number of bound servers
+`{{numBoundCategories}}`    | Number of bound categories
 `{{numBoundChannels}}`      | Number of bound channels
 `{{numAdminChannels}}`      | Number of admin channels
 `{{numAdmins}}`             | Number of designated admins

+ 4 - 0
commands.go

@@ -111,14 +111,18 @@ func handleCommands() *exrouter.Route {
 					"• **Started at —** %s\n"+
 					"• **Joined Servers —** %d\n"+
 					"• **Bound Channels —** %d\n"+
+					"• **Bound Cagetories —** %d\n"+
 					"• **Bound Servers —** %d\n"+
+					"• **Bound Users —** %d\n"+
 					"• **Admin Channels —** %d\n"+
 					"• **Heartbeat Latency —** %dms",
 					durafmt.Parse(time.Since(startTime)).String(),
 					startTime.Format("03:04:05pm on Monday, January 2, 2006 (MST)"),
 					len(bot.State.Guilds),
 					getBoundChannelsCount(),
+					getBoundCategoriesCount(),
 					getBoundServersCount(),
+					getBoundUsersCount(),
 					len(config.AdminChannels),
 					bot.HeartbeatLatency().Milliseconds(),
 				)

+ 48 - 0
config.go

@@ -1057,6 +1057,30 @@ func isCommandableChannel(m *discordgo.Message) bool {
 	return false
 }
 
+func getBoundUsers() []string {
+	var users []string
+	for _, item := range config.Users {
+		if item.UserID != "" {
+			if !stringInSlice(item.UserID, users) {
+				users = append(users, item.UserID)
+			}
+		} else if item.UserIDs != nil {
+			for _, subuser := range *item.UserIDs {
+				if subuser != "" {
+					if !stringInSlice(subuser, users) {
+						users = append(users, subuser)
+					}
+				}
+			}
+		}
+	}
+	return users
+}
+
+func getBoundUsersCount() int {
+	return len(getBoundUsers())
+}
+
 func getBoundServers() []string {
 	var servers []string
 	for _, item := range config.Servers {
@@ -1105,6 +1129,30 @@ func getBoundChannelsCount() int {
 	return len(getBoundChannels())
 }
 
+func getBoundCategories() []string {
+	var categories []string
+	for _, item := range config.Categories {
+		if item.CategoryID != "" {
+			if !stringInSlice(item.CategoryID, categories) {
+				categories = append(categories, item.CategoryID)
+			}
+		} else if item.CategoryIDs != nil {
+			for _, subcategory := range *item.CategoryIDs {
+				if subcategory != "" {
+					if !stringInSlice(subcategory, categories) {
+						categories = append(categories, subcategory)
+					}
+				}
+			}
+		}
+	}
+	return categories
+}
+
+func getBoundCategoriesCount() int {
+	return len(getBoundCategories())
+}
+
 func getAllRegisteredChannels() []string {
 	var channels []string
 	if config.All != nil { // ALL MODE

+ 14 - 2
discord.go

@@ -198,7 +198,9 @@ func dataKeyReplacement(input string) string {
 			{"{{countShort}}", formatNumberShort(countInt)},
 			{"{{numServers}}", fmt.Sprint(len(bot.State.Guilds))},
 			{"{{numBoundChannels}}", fmt.Sprint(getBoundChannelsCount())},
+			{"{{numBoundCategories}}", fmt.Sprint(getBoundCategoriesCount())},
 			{"{{numBoundServers}}", fmt.Sprint(getBoundServersCount())},
+			{"{{numBoundUsers}}", fmt.Sprint(getBoundUsersCount())},
 			{"{{numAdminChannels}}", fmt.Sprint(len(config.AdminChannels))},
 			{"{{numAdmins}}", fmt.Sprint(len(config.Admins))},
 			{"{{timeSavedShort}}", timeLastUpdated.Format("3:04pm")},
@@ -542,7 +544,12 @@ func sendStatusMessage(status sendStatusType) {
 				message += fmt.Sprintf("%s %s and connected to %d server%s...\n", projectLabel, sendStatusLabel(status), len(bot.State.Guilds), pluralS(len(bot.State.Guilds)))
 				message += fmt.Sprintf("\n• Uptime is %s", uptime())
 				message += fmt.Sprintf("\n• %s total downloads", formatNumber(int64(dbDownloadCount())))
-				message += fmt.Sprintf("\n• Bound to %d channel%s and %d server%s", getBoundChannelsCount(), pluralS(getBoundChannelsCount()), getBoundServersCount(), pluralS(getBoundServersCount()))
+				message += fmt.Sprintf("\n• Bound to %d channel%s, %d categories, %d server%s, %d user%s",
+					getBoundChannelsCount(), pluralS(getBoundChannelsCount()),
+					getBoundCategoriesCount(),
+					getBoundServersCount(), pluralS(getBoundServersCount()),
+					getBoundUsersCount(), pluralS(getBoundUsersCount()),
+				)
 				if config.All != nil {
 					message += "\n• **ALL MODE ENABLED -** Bot will use all available channels"
 				}
@@ -561,7 +568,12 @@ func sendStatusMessage(status sendStatusType) {
 				message += fmt.Sprintf("%s %s...\n", projectLabel, sendStatusLabel(status))
 				message += fmt.Sprintf("\n• Uptime was %s", uptime())
 				message += fmt.Sprintf("\n• %s total downloads", formatNumber(int64(dbDownloadCount())))
-				message += fmt.Sprintf("\n• Bound to %d channel%s and %d server%s", getBoundChannelsCount(), pluralS(getBoundChannelsCount()), getBoundServersCount(), pluralS(getBoundServersCount()))
+				message += fmt.Sprintf("\n• Bound to %d channel%s, %d categories, %d server%s, %d user%s",
+					getBoundChannelsCount(), pluralS(getBoundChannelsCount()),
+					getBoundCategoriesCount(),
+					getBoundServersCount(), pluralS(getBoundServersCount()),
+					getBoundUsersCount(), pluralS(getBoundUsersCount()),
+				)
 			}
 			// Send
 			if config.DebugOutput {

+ 15 - 2
main.go

@@ -113,9 +113,16 @@ func init() {
 func main() {
 	//#region Config
 	loadConfig()
-	log.Println(lg("Settings", "", color.HiYellowString, "Loaded - bound to %d channel%s and %d server%s",
+	allString := ""
+	if config.All != nil {
+		allString = ", ALL ENABLED"
+	}
+	log.Println(lg("Settings", "", color.HiYellowString,
+		"Loaded - bound to %d channel%s, %d categories, %d server%s, %d user%s%s",
 		getBoundChannelsCount(), pluralS(getBoundChannelsCount()),
+		getBoundCategoriesCount(),
 		getBoundServersCount(), pluralS(getBoundServersCount()),
+		getBoundUsersCount(), pluralS(getBoundUsersCount()), allString,
 	))
 	//#endregion
 
@@ -439,10 +446,16 @@ func main() {
 						log.Println(lg("Settings", "Watcher", color.YellowString,
 							"Detected changes in \"%s\", reloading...", configFile))
 						loadConfig()
+						allString := ""
+						if config.All != nil {
+							allString = ", ALL ENABLED"
+						}
 						log.Println(lg("Settings", "Watcher", color.HiYellowString,
-							"Reloaded - bound to %d channel%s and %d server%s",
+							"Reloaded - bound to %d channel%s, %d categories, %d server%s, %d user%s%s",
 							getBoundChannelsCount(), pluralS(getBoundChannelsCount()),
+							getBoundCategoriesCount(),
 							getBoundServersCount(), pluralS(getBoundServersCount()),
+							getBoundUsersCount(), pluralS(getBoundUsersCount()), allString,
 						))
 
 						updateDiscordPresence()