mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-11-25 01:44:12 +00:00
Add blocking commands
This commit is contained in:
parent
e73c05b819
commit
59820bced1
2 changed files with 83 additions and 16 deletions
|
@ -10,6 +10,7 @@ namespace BirthdayBot.ApplicationCommands;
|
||||||
public class ConfigModule : BotModuleBase {
|
public class ConfigModule : BotModuleBase {
|
||||||
public const string HelpCmdConfig = "Configure basic settings for the bot.";
|
public const string HelpCmdConfig = "Configure basic settings for the bot.";
|
||||||
public const string HelpCmdAnnounce = "Settings regarding birthday announcements.";
|
public const string HelpCmdAnnounce = "Settings regarding birthday announcements.";
|
||||||
|
public const string HelpCmdBlocking = "Settings for limiting user access.";
|
||||||
public const string HelpCmdRole = "Settings for roles used by this bot.";
|
public const string HelpCmdRole = "Settings for roles used by this bot.";
|
||||||
public const string HelpCmdCheck = "Test the bot's current configuration and show the results.";
|
public const string HelpCmdCheck = "Test the bot's current configuration and show the results.";
|
||||||
|
|
||||||
|
@ -19,14 +20,39 @@ public class ConfigModule : BotModuleBase {
|
||||||
|
|
||||||
[Group("announce", HelpPfxModOnly + HelpCmdAnnounce)]
|
[Group("announce", HelpPfxModOnly + HelpCmdAnnounce)]
|
||||||
public class SubCmdsConfigAnnounce : BotModuleBase {
|
public class SubCmdsConfigAnnounce : BotModuleBase {
|
||||||
|
private const string HelpSubCmdChannel = "Set which channel will receive announcement messages.";
|
||||||
|
private const string HelpSubCmdMessage = "Modify the announcement message.";
|
||||||
|
private const string HelpSubCmdPing = "Set whether to ping users mentioned in the announcement.";
|
||||||
|
|
||||||
[SlashCommand("help", "Show information regarding announcement messages.")]
|
[SlashCommand("help", "Show information regarding announcement messages.")]
|
||||||
public async Task CmdAnnounceHelp() {
|
public async Task CmdAnnounceHelp() {
|
||||||
// TODO
|
const string subcommands =
|
||||||
await RespondAsync("hi");
|
$"`/config announce` - {HelpCmdAnnounce}\n" +
|
||||||
throw new NotImplementedException();
|
$" ⤷`set-channel` - {HelpSubCmdChannel}\n" +
|
||||||
|
$" ⤷`set-message` - {HelpSubCmdMessage}\n" +
|
||||||
|
$" ⤷`set-ping` - {HelpSubCmdPing}";
|
||||||
|
const string whatIs =
|
||||||
|
"As the name implies, an announcement message is the messages displayed when somebody's birthday be" +
|
||||||
|
"arrives. If enabled, an announcment message is shown at midnight respective to the appropriate time zone, " +
|
||||||
|
"first using the user's local time (if it is known), or else using the server's default time zone, or else " +
|
||||||
|
"referring back to midnight in Universal Time (UTC).\n\n" +
|
||||||
|
"To enable announcement messages, use the `set-channel` subcommand.";
|
||||||
|
const string editMsg =
|
||||||
|
"The `set-message` subcommand allow moderators to edit the message sent into the announcement channel.\n" +
|
||||||
|
"Two messages may be provided: `single` sets the message that is displayed when one user has a birthday, and " +
|
||||||
|
"`multi` sets the message used when two or more users have birthdays. If only one of the two messages " +
|
||||||
|
"have been set, this bot will use the same message in both cases.\n\n" +
|
||||||
|
"You may use the token `%n` in your message to specify where the name(s) should appear, otherwise the names " +
|
||||||
|
"will appear at the very end of your custom message.";
|
||||||
|
await RespondAsync(embed: new EmbedBuilder()
|
||||||
|
.WithAuthor("Announcement configuration")
|
||||||
|
.WithDescription(subcommands)
|
||||||
|
.AddField("What is an announcement message?", whatIs)
|
||||||
|
.AddField("Customization", editMsg)
|
||||||
|
.Build()).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[SlashCommand("set-channel", HelpPfxModOnly + "Set which channel will receive announcement messages." + HelpPofxBlankUnset)]
|
[SlashCommand("set-channel", HelpPfxModOnly + HelpSubCmdChannel + HelpPofxBlankUnset)]
|
||||||
public async Task CmdSetChannel([Summary(description: HelpOptRole)] SocketTextChannel? channel = null) {
|
public async Task CmdSetChannel([Summary(description: HelpOptRole)] SocketTextChannel? channel = null) {
|
||||||
var gconf = await Context.Guild.GetConfigAsync().ConfigureAwait(false);
|
var gconf = await Context.Guild.GetConfigAsync().ConfigureAwait(false);
|
||||||
gconf.AnnounceChannelId = channel?.Id;
|
gconf.AnnounceChannelId = channel?.Id;
|
||||||
|
@ -35,19 +61,21 @@ public class ConfigModule : BotModuleBase {
|
||||||
(channel == null ? "unset." : $"set to **{channel.Name}**."));
|
(channel == null ? "unset." : $"set to **{channel.Name}**."));
|
||||||
}
|
}
|
||||||
|
|
||||||
[SlashCommand("set-message", HelpPfxModOnly + "Modify the announcement message.")]
|
[SlashCommand("set-message", HelpPfxModOnly + HelpSubCmdMessage)]
|
||||||
public async Task CmdSetMessage() {
|
public async Task CmdSetMessage() {
|
||||||
// TODO fully implement this
|
// TODO implement this
|
||||||
await RespondAsync("Sorry, changing the announcement message via slash commands is not yet available. " +
|
var pfx = TextCommands.CommandsCommon.CommandPrefix;
|
||||||
"Please use the corresponding text command.", ephemeral: true);
|
await RespondAsync(":x: Sorry, changing the announcement message via slash commands is not yet available. " +
|
||||||
|
"Please use the corresponding text command: " +
|
||||||
|
$"`{pfx}config message` for single, `{pfx}config message-pl` for multi.", ephemeral: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
[SlashCommand("set-ping", HelpPfxModOnly + "Set whether to ping users mentioned in the announcement.")]
|
[SlashCommand("set-ping", HelpPfxModOnly + HelpSubCmdPing)]
|
||||||
public async Task CmdSetPing([Summary(description: "Set True to ping users, False to display them normally.")]bool option) {
|
public async Task CmdSetPing([Summary(description: "Set True to ping users, False to display them normally.")]bool option) {
|
||||||
var gconf = await Context.Guild.GetConfigAsync().ConfigureAwait(false);
|
var gconf = await Context.Guild.GetConfigAsync().ConfigureAwait(false);
|
||||||
gconf.AnnouncePing = option;
|
gconf.AnnouncePing = option;
|
||||||
await gconf.UpdateAsync().ConfigureAwait(false);
|
await gconf.UpdateAsync().ConfigureAwait(false);
|
||||||
await RespondAsync(":white_check_mark: Announcement pings are now " + (option ? "**on**." : "**off**.")).ConfigureAwait(false);
|
await RespondAsync($":white_check_mark: Announcement pings are now **{(option ? "on" : "off")}**.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +99,41 @@ public class ConfigModule : BotModuleBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Group("block", HelpCmdBlocking)]
|
||||||
|
public class SubCmdsConfigBlocking : BotModuleBase {
|
||||||
|
[SlashCommand("add-block", HelpPfxModOnly + "Add a user to the block list.")]
|
||||||
|
public Task CmdAddBlock([Summary(description: "The user to block.")] SocketGuildUser user) => DoBlocklist(user.Id, true);
|
||||||
|
|
||||||
|
[SlashCommand("remove-block", HelpPfxModOnly + "Remove a user from the block list.")]
|
||||||
|
public Task CmdDelBlock([Summary(description: "The user to unblock.")] SocketGuildUser user) => DoBlocklist(user.Id, false);
|
||||||
|
|
||||||
|
private async Task DoBlocklist(ulong userId, bool setting) {
|
||||||
|
var gconf = await Context.Guild.GetConfigAsync().ConfigureAwait(false);
|
||||||
|
bool already = setting == await gconf.IsUserBlockedAsync(userId).ConfigureAwait(false);
|
||||||
|
if (already) {
|
||||||
|
// TODO bug: this may sometimes be misleading when in moderated mode
|
||||||
|
await ReplyAsync($":white_check_mark: User is already {(setting ? "" : "not ")}blocked.").ConfigureAwait(false);
|
||||||
|
} else {
|
||||||
|
if (setting) await gconf.BlockUserAsync(userId).ConfigureAwait(false);
|
||||||
|
else await gconf.UnblockUserAsync(userId).ConfigureAwait(false);
|
||||||
|
await ReplyAsync($":white_check_mark: User has been {(setting ? "" : "un")}blocked.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[SlashCommand("set-moderated", HelpPfxModOnly + "Set moderated mode on the server.")]
|
||||||
|
public async Task CmdAddBlock([Summary(name: "enable", description: "The moderated mode setting.")] bool setting) {
|
||||||
|
var gconf = await Context.Guild.GetConfigAsync().ConfigureAwait(false);
|
||||||
|
bool already = setting == gconf.IsModerated;
|
||||||
|
if (already) {
|
||||||
|
await RespondAsync($":white_check_mark: Moderated mode is already **{(setting ? "en" : "dis")}abled**.").ConfigureAwait(false);
|
||||||
|
} else {
|
||||||
|
gconf.IsModerated = setting;
|
||||||
|
await gconf.UpdateAsync().ConfigureAwait(false);
|
||||||
|
await RespondAsync($":white_check_mark: Moderated mode is now **{(setting ? "en" : "dis")}abled**.").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[SlashCommand("check", HelpPfxModOnly + HelpCmdCheck)]
|
[SlashCommand("check", HelpPfxModOnly + HelpCmdCheck)]
|
||||||
public async Task CmdCheck() {
|
public async Task CmdCheck() {
|
||||||
static string DoTestFor(string label, Func<bool> test) => $"{label}: { (test() ? ":white_check_mark: Yes" : ":x: No") }";
|
static string DoTestFor(string label, Func<bool> test) => $"{label}: { (test() ? ":white_check_mark: Yes" : ":x: No") }";
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
namespace BirthdayBot.ApplicationCommands;
|
namespace BirthdayBot.ApplicationCommands;
|
||||||
|
|
||||||
public class HelpModule : BotModuleBase {
|
public class HelpModule : BotModuleBase {
|
||||||
|
private const string TopMessage =
|
||||||
|
"Thank you for using Birthday Bot!\n" +
|
||||||
|
"Support, data policy, more info: https://noithecat.dev/bots/BirthdayBot\n\n" +
|
||||||
|
"This bot is provided for free, without any paywalls or exclusive paid features. If this bot has been useful to you, " +
|
||||||
|
"please consider making a small contribution via the author's Ko-fi: https://ko-fi.com/noithecat.";
|
||||||
private const string RegularCommandsField =
|
private const string RegularCommandsField =
|
||||||
$"`/birthday` - {BirthdayModule.HelpCmdBirthday}\n" +
|
$"`/birthday` - {BirthdayModule.HelpCmdBirthday}\n" +
|
||||||
$"` ⤷get` - {BirthdayModule.HelpCmdGet}\n" +
|
$"` ⤷get` - {BirthdayModule.HelpCmdGet}\n" +
|
||||||
|
@ -16,6 +21,8 @@ public class HelpModule : BotModuleBase {
|
||||||
$"` ⤷check` - {ConfigModule.HelpCmdCheck}\n" +
|
$"` ⤷check` - {ConfigModule.HelpCmdCheck}\n" +
|
||||||
$"` ⤷announce` - {ConfigModule.HelpCmdAnnounce}\n" +
|
$"` ⤷announce` - {ConfigModule.HelpCmdAnnounce}\n" +
|
||||||
$"` ⤷` See also: `/config announce help`.\n" +
|
$"` ⤷` See also: `/config announce help`.\n" +
|
||||||
|
$"` ⤷blocking` - {ConfigModule.HelpCmdBlocking}\n" +
|
||||||
|
$"` ⤷add-block`, `⤷remove-block`, `⤷set-moderated`\n" +
|
||||||
$"` ⤷role` - {ConfigModule.HelpCmdRole}\n" +
|
$"` ⤷role` - {ConfigModule.HelpCmdRole}\n" +
|
||||||
$"` ⤷set-birthday-role`, `⤷set-moderator-role`\n" +
|
$"` ⤷set-birthday-role`, `⤷set-moderator-role`\n" +
|
||||||
$"`/override` - {BirthdayOverrideModule.HelpCmdOverride}\n" +
|
$"`/override` - {BirthdayOverrideModule.HelpCmdOverride}\n" +
|
||||||
|
@ -25,7 +32,7 @@ public class HelpModule : BotModuleBase {
|
||||||
[SlashCommand("help", "Show an overview of available commands.")]
|
[SlashCommand("help", "Show an overview of available commands.")]
|
||||||
public async Task CmdHelp() {
|
public async Task CmdHelp() {
|
||||||
const string DMWarn = "Please note that this bot works in servers only. " +
|
const string DMWarn = "Please note that this bot works in servers only. " +
|
||||||
"The bot will not respond to any of the following commands within a DM.";
|
"The bot will not respond to any other commands within a DM.";
|
||||||
|
|
||||||
string ver =
|
string ver =
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
@ -37,10 +44,7 @@ public class HelpModule : BotModuleBase {
|
||||||
.WithAuthor("Help & About")
|
.WithAuthor("Help & About")
|
||||||
.WithFooter($"Birthday Bot {ver} - Shard {Shard.ShardId:00} up {Program.BotUptime}",
|
.WithFooter($"Birthday Bot {ver} - Shard {Shard.ShardId:00} up {Program.BotUptime}",
|
||||||
Context.Client.CurrentUser.GetAvatarUrl())
|
Context.Client.CurrentUser.GetAvatarUrl())
|
||||||
.WithDescription("Thank you for using Birthday Bot!\n" +
|
.WithDescription(TopMessage)
|
||||||
"Support, data policy, more info: https://noithecat.dev/bots/BirthdayBot\n\n" +
|
|
||||||
"This bot is provided for free, without any paywalls or exclusive paid features. If this bot has been useful to you, " +
|
|
||||||
"please consider making a small contribution via the author's Ko-fi: https://ko-fi.com/noithecat.")
|
|
||||||
.AddField("Commands", RegularCommandsField)
|
.AddField("Commands", RegularCommandsField)
|
||||||
.AddField("Moderator commands", ModCommandsField)
|
.AddField("Moderator commands", ModCommandsField)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
Loading…
Reference in a new issue