From acb23d255a2bea6ef39a6f6acea479ab96e5ca72 Mon Sep 17 00:00:00 2001 From: 13xforever Date: Mon, 2 Nov 2020 18:24:03 +0500 Subject: [PATCH] remove hardcoded bot admin id, use application owners data instead --- CompatBot/Commands/Sudo.Mod.cs | 4 ++-- CompatBot/Config.cs | 1 - CompatBot/Database/DbImporter.cs | 5 ----- CompatBot/Program.cs | 15 +++++++++++++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CompatBot/Commands/Sudo.Mod.cs b/CompatBot/Commands/Sudo.Mod.cs index ced0efc9..53ab2399 100644 --- a/CompatBot/Commands/Sudo.Mod.cs +++ b/CompatBot/Commands/Sudo.Mod.cs @@ -34,7 +34,7 @@ namespace CompatBot.Commands [Description("Removes a moderator")] public async Task Remove(CommandContext ctx, [Description("Discord user to remove from the bot mod list")] DiscordMember user) { - if (user.Id == Config.BotAdminId) + if (ctx.Client.CurrentApplication.Owners.Any(u => u.Id == user.Id)) { var dm = await user.CreateDmChannelAsync().ConfigureAwait(false); await dm.SendMessageAsync($@"Just letting you know that {ctx.Message.Author.Mention} just tried to strip you off of your mod role ¯\\_(ツ)_/¯").ConfigureAwait(false); @@ -78,7 +78,7 @@ namespace CompatBot.Commands [Description("Makes a sudoer a regular moderator")] public async Task Unsudo(CommandContext ctx, [Description("Discord user on the moderator list to strip the sudoer rights from")] DiscordMember sudoer) { - if (sudoer.Id == Config.BotAdminId) + if (ctx.Client.CurrentApplication.Owners.Any(u => u.Id == sudoer.Id)) { var dm = await sudoer.CreateDmChannelAsync().ConfigureAwait(false); await dm.SendMessageAsync($@"Just letting you know that {ctx.Message.Author.Mention} just tried to strip you off of your sudo permissions ¯\\_(ツ)_/¯").ConfigureAwait(false); diff --git a/CompatBot/Config.cs b/CompatBot/Config.cs index 853d4b70..1dc5a9c7 100644 --- a/CompatBot/Config.cs +++ b/CompatBot/Config.cs @@ -53,7 +53,6 @@ namespace CompatBot public static ulong BotLogId => config.GetValue(nameof(BotLogId), 436972161572536329ul); // #bot-log; a private channel for admin mod queue public static ulong BotRulesChannelId => config.GetValue(nameof(BotRulesChannelId), 311894275015049216ul); // #rules-info; used to give links to rules public static ulong ThumbnailSpamId => config.GetValue(nameof(ThumbnailSpamId), 475678410098606100ul); // #bot-data; used for whatever bot needs to keep (cover embeds, etc) - public static ulong BotAdminId => config.GetValue(nameof(BotAdminId), 267367850706993152ul); // discord user id for a bot admin public static ulong DeletedMessagesLogChannelId => config.GetValue(nameof(DeletedMessagesLogChannelId), 0ul); public static TimeSpan ModerationBacklogThresholdInHours => TimeSpan.FromHours(config.GetValue(nameof(ModerationBacklogThresholdInHours), 1)); diff --git a/CompatBot/Database/DbImporter.cs b/CompatBot/Database/DbImporter.cs index 8e361b73..2f08780e 100644 --- a/CompatBot/Database/DbImporter.cs +++ b/CompatBot/Database/DbImporter.cs @@ -38,11 +38,6 @@ namespace CompatBot.Database return false; } } - if (dbContext is BotDb botDb2 && !await botDb2.Moderator.AnyAsync(m => m.DiscordId == Config.BotAdminId, cancellationToken).ConfigureAwait(false)) - { - await botDb2.Moderator.AddAsync(new Moderator {DiscordId = Config.BotAdminId, Sudoer = true}, cancellationToken).ConfigureAwait(false); - await dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false); - } Config.Log.Info("Database is ready."); return true; } diff --git a/CompatBot/Program.cs b/CompatBot/Program.cs index 911ec823..eb9de3cf 100644 --- a/CompatBot/Program.cs +++ b/CompatBot/Program.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; +using System.Text; using System.Threading; using System.Threading.Tasks; using CompatBot.Commands; @@ -16,6 +17,7 @@ using DSharpPlus.CommandsNext; using DSharpPlus.Entities; using DSharpPlus.Interactivity; using DSharpPlus.Interactivity.Extensions; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration.UserSecrets; using Microsoft.Extensions.DependencyInjection; @@ -171,11 +173,20 @@ namespace CompatBot client.Ready += async (c, _) => { - var admin = await c.GetUserAsync(Config.BotAdminId).ConfigureAwait(false); Config.Log.Info("Bot is ready to serve!"); Config.Log.Info(""); Config.Log.Info($"Bot user id : {c.CurrentUser.Id} ({c.CurrentUser.Username})"); - Config.Log.Info($"Bot admin id : {Config.BotAdminId} ({admin.Username ?? "???"}#{admin.Discriminator ?? "????"})"); + var owners = c.CurrentApplication.Owners.ToList(); + var msg = new StringBuilder($"Bot admin id{(owners.Count == 1 ? "": "s")}:"); + using var db = new BotDb(); + foreach (var owner in owners) + { + msg.AppendLine().Append($"\t{owner.Id} ({owner.Username ?? "???"}#{owner.Discriminator ?? "????"})"); + if (!await db.Moderator.AnyAsync(m => m.DiscordId == owner.Id, Config.Cts.Token).ConfigureAwait(false)) + await db.Moderator.AddAsync(new Moderator {DiscordId = owner.Id, Sudoer = true}, Config.Cts.Token).ConfigureAwait(false); + } + await db.SaveChangesAsync(Config.Cts.Token).ConfigureAwait(false); + Config.Log.Info(msg); Config.Log.Info(""); }; client.GuildAvailable += async (c, gaArgs) =>