mirror of
https://github.com/NoiTheCat/WorldTime.git
synced 2024-11-21 14:34:36 +00:00
Add setting to allow private confirmation of commands
With some exceptions: for the sake of transparency, positive confirmations of moderator commands will still always be shown.
This commit is contained in:
parent
2861b579b4
commit
b5b7725df1
3 changed files with 46 additions and 12 deletions
|
@ -8,9 +8,13 @@ public class ConfigCommands : CommandsBase {
|
|||
internal const string HelpUse12 = "Sets whether to use the 12-hour (AM/PM) format in time zone listings.";
|
||||
internal const string HelpSetFor = "Sets/updates time zone for a given user.";
|
||||
internal const string HelpRemoveFor = "Removes time zone for a given user.";
|
||||
internal const string HelpPrivateConfirms
|
||||
= "Sets whether to make confirmations for commands visible only to the user, except set-for and remove-for.";
|
||||
|
||||
internal const string HelpBool = "True to enable, False to disable.";
|
||||
|
||||
[SlashCommand("use-12hour", HelpUse12)]
|
||||
public async Task Cmd12Hour([Summary(description: "True to enable, False to disable.")] bool setting) {
|
||||
public async Task Cmd12Hour([Summary(description: HelpBool)] bool setting) {
|
||||
using var db = DbContext;
|
||||
var gs = db.GuildSettings.Where(r => r.GuildId == Context.Guild.Id).SingleOrDefault();
|
||||
if (gs == null) {
|
||||
|
@ -19,31 +23,51 @@ public class ConfigCommands : CommandsBase {
|
|||
}
|
||||
|
||||
gs.Use12HourTime = setting;
|
||||
await db.SaveChangesAsync();
|
||||
await RespondAsync($":white_check_mark: Time listing set to **{(setting ? "AM/PM" : "24 hour")}** format.");
|
||||
await db.SaveChangesAsync().ConfigureAwait(false);
|
||||
await RespondAsync($":white_check_mark: Time listing set to **{(setting ? "AM/PM" : "24 hour")}** format.",
|
||||
ephemeral: gs.EphemeralConfirm).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[SlashCommand("private-confirms", HelpPrivateConfirms)]
|
||||
public async Task PrivateConfirmations([Summary(description: HelpBool)] bool setting) {
|
||||
using var db = DbContext;
|
||||
var gs = db.GuildSettings.Where(r => r.GuildId == Context.Guild.Id).SingleOrDefault();
|
||||
if (gs == null) {
|
||||
gs = new() { GuildId = Context.Guild.Id };
|
||||
db.Add(gs);
|
||||
}
|
||||
|
||||
gs.EphemeralConfirm = setting;
|
||||
await db.SaveChangesAsync().ConfigureAwait(false);
|
||||
await RespondAsync($":white_check_mark: Private confirmations **{(setting ? "enabled" : "disabled")}**.",
|
||||
ephemeral: false).ConfigureAwait(false); // Always show this confirmation despite setting
|
||||
}
|
||||
|
||||
[SlashCommand("set-for", HelpSetFor)]
|
||||
public async Task CmdSetFor([Summary(description: "The user whose time zone to modify.")] SocketGuildUser user,
|
||||
[Summary(description: "The new time zone to set.")] string zone) {
|
||||
using var db = DbContext;
|
||||
// Extract parameters
|
||||
var newtz = ParseTimeZone(zone);
|
||||
if (newtz == null) {
|
||||
await RespondAsync(ErrInvalidZone);
|
||||
await RespondAsync(ErrInvalidZone,
|
||||
ephemeral: db.GuildSettings.Where(r => r.GuildId == Context.Guild.Id).SingleOrDefault()?.EphemeralConfirm ?? false)
|
||||
.ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
using var db = DbContext;
|
||||
db.UpdateUser(user, newtz);
|
||||
await RespondAsync($":white_check_mark: Time zone for **{user}** set to **{newtz}**.");
|
||||
await RespondAsync($":white_check_mark: Time zone for **{user}** set to **{newtz}**.").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[SlashCommand("remove-for", HelpRemoveFor)]
|
||||
public async Task CmdRemoveFor([Summary(description: "The user whose time zone to remove.")] SocketGuildUser user) {
|
||||
using var db = DbContext;
|
||||
if (db.DeleteUser(user))
|
||||
await RespondAsync($":white_check_mark: Removed zone information for {user}.");
|
||||
await RespondAsync($":white_check_mark: Removed zone information for {user}.").ConfigureAwait(false);
|
||||
else
|
||||
await RespondAsync($":white_check_mark: No time zone is set for {user}.");
|
||||
await RespondAsync($":white_check_mark: No time zone is set for {user}.",
|
||||
ephemeral: db.GuildSettings.Where(r => r.GuildId == Context.Guild.Id).SingleOrDefault()?.EphemeralConfirm ?? false)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ public class UserCommands : CommandsBase {
|
|||
+ $"`/remove` - {HelpRemove}";
|
||||
const string EmbedHelpField2 =
|
||||
$"`/config use-12hour` - {ConfigCommands.HelpUse12}\n"
|
||||
+ $"`/config private-confirms` - {ConfigCommands.HelpPrivateConfirms}\n"
|
||||
+ $"`/set-for` - {ConfigCommands.HelpSetFor}\n"
|
||||
+ $"`/remove-for` - {ConfigCommands.HelpRemoveFor}";
|
||||
|
||||
|
@ -67,7 +68,8 @@ public class UserCommands : CommandsBase {
|
|||
using var db = DbContext;
|
||||
var userlist = db.GetGuildZones(Context.Guild.Id);
|
||||
if (userlist.Count == 0) {
|
||||
await RespondAsync(":x: Nothing to show. Register your time zones with the bot using the `/set` command.");
|
||||
await RespondAsync(":x: Nothing to show. Register your time zones with the bot using the `/set` command.",
|
||||
ephemeral: true).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -157,7 +159,9 @@ public class UserCommands : CommandsBase {
|
|||
}
|
||||
using var db = DbContext;
|
||||
db.UpdateUser((SocketGuildUser)Context.User, parsedzone);
|
||||
await RespondAsync($":white_check_mark: Your time zone has been set to **{parsedzone}**.");
|
||||
await RespondAsync($":white_check_mark: Your time zone has been set to **{parsedzone}**.",
|
||||
ephemeral: db.GuildSettings.Where(r => r.GuildId == Context.Guild.Id).SingleOrDefault()?.EphemeralConfirm ?? false)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[SlashCommand("remove", HelpRemove)]
|
||||
|
@ -165,7 +169,11 @@ public class UserCommands : CommandsBase {
|
|||
public async Task CmdRemove() {
|
||||
using var db = DbContext;
|
||||
var success = db.DeleteUser((SocketGuildUser)Context.User);
|
||||
if (success) await RespondAsync(":white_check_mark: Your zone has been removed.");
|
||||
else await RespondAsync(":x: You don't have a time zone set.");
|
||||
if (success) await RespondAsync(":white_check_mark: Your zone has been removed.",
|
||||
ephemeral: db.GuildSettings.Where(r => r.GuildId == Context.Guild.Id).SingleOrDefault()?.EphemeralConfirm ?? false)
|
||||
.ConfigureAwait(false);
|
||||
else await RespondAsync(":x: You don't have a time zone set.",
|
||||
ephemeral: db.GuildSettings.Where(r => r.GuildId == Context.Guild.Id).SingleOrDefault()?.EphemeralConfirm ?? false)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,4 +6,6 @@ public class GuildConfiguration {
|
|||
public ulong GuildId { get; set; }
|
||||
|
||||
public bool Use12HourTime { get; set; }
|
||||
|
||||
public bool EphemeralConfirm { get; set; }
|
||||
}
|
Loading…
Reference in a new issue