diff --git a/Commands/ConfigCommands.cs b/Commands/ConfigCommands.cs
index 8c81f8e..8b4dcb9 100644
--- a/Commands/ConfigCommands.cs
+++ b/Commands/ConfigCommands.cs
@@ -8,9 +8,12 @@ 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 set/update confirmations visible only to the user.";
+
+ 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 +22,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);
}
}
\ No newline at end of file
diff --git a/Commands/UserCommands.cs b/Commands/UserCommands.cs
index 8e0345a..d7c26ea 100644
--- a/Commands/UserCommands.cs
+++ b/Commands/UserCommands.cs
@@ -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);
}
}
diff --git a/Data/GuildConfiguration.cs b/Data/GuildConfiguration.cs
index 6339bd7..ed5e040 100644
--- a/Data/GuildConfiguration.cs
+++ b/Data/GuildConfiguration.cs
@@ -6,4 +6,6 @@ public class GuildConfiguration {
public ulong GuildId { get; set; }
public bool Use12HourTime { get; set; }
+
+ public bool EphemeralConfirm { get; set; }
}
\ No newline at end of file
diff --git a/Data/Migrations/20230909184554_AddEphemeral.Designer.cs b/Data/Migrations/20230909184554_AddEphemeral.Designer.cs
new file mode 100644
index 0000000..ba67531
--- /dev/null
+++ b/Data/Migrations/20230909184554_AddEphemeral.Designer.cs
@@ -0,0 +1,73 @@
+//
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+using WorldTime.Data;
+
+#nullable disable
+
+namespace WorldTime.Data.Migrations
+{
+ [DbContext(typeof(BotDatabaseContext))]
+ [Migration("20230909184554_AddEphemeral")]
+ partial class AddEphemeral
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.2")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("WorldTime.Data.GuildConfiguration", b =>
+ {
+ b.Property("GuildId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("numeric(20,0)")
+ .HasColumnName("guild_id");
+
+ b.Property("EphemeralConfirm")
+ .HasColumnType("boolean")
+ .HasColumnName("ephemeral_confirm");
+
+ b.Property("Use12HourTime")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("boolean")
+ .HasDefaultValue(false)
+ .HasColumnName("use12hour_time");
+
+ b.HasKey("GuildId")
+ .HasName("pk_guild_settings");
+
+ b.ToTable("guild_settings", (string)null);
+ });
+
+ modelBuilder.Entity("WorldTime.Data.UserEntry", b =>
+ {
+ b.Property("GuildId")
+ .HasColumnType("bigint")
+ .HasColumnName("guild_id");
+
+ b.Property("UserId")
+ .HasColumnType("bigint")
+ .HasColumnName("user_id");
+
+ b.Property("TimeZone")
+ .IsRequired()
+ .HasColumnType("text")
+ .HasColumnName("zone");
+
+ b.HasKey("GuildId", "UserId")
+ .HasName("userdata_pkey");
+
+ b.ToTable("userdata", (string)null);
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Data/Migrations/20230909184554_AddEphemeral.cs b/Data/Migrations/20230909184554_AddEphemeral.cs
new file mode 100644
index 0000000..4d545fe
--- /dev/null
+++ b/Data/Migrations/20230909184554_AddEphemeral.cs
@@ -0,0 +1,29 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace WorldTime.Data.Migrations
+{
+ ///
+ public partial class AddEphemeral : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AddColumn(
+ name: "ephemeral_confirm",
+ table: "guild_settings",
+ type: "boolean",
+ nullable: false,
+ defaultValue: false);
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropColumn(
+ name: "ephemeral_confirm",
+ table: "guild_settings");
+ }
+ }
+}
diff --git a/Data/Migrations/BotDatabaseContextModelSnapshot.cs b/Data/Migrations/BotDatabaseContextModelSnapshot.cs
index 63704a5..46c20c4 100644
--- a/Data/Migrations/BotDatabaseContextModelSnapshot.cs
+++ b/Data/Migrations/BotDatabaseContextModelSnapshot.cs
@@ -16,7 +16,7 @@ namespace WorldTime.Data.Migrations
{
#pragma warning disable 612, 618
modelBuilder
- .HasAnnotation("ProductVersion", "7.0.1")
+ .HasAnnotation("ProductVersion", "7.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@@ -28,6 +28,10 @@ namespace WorldTime.Data.Migrations
.HasColumnType("numeric(20,0)")
.HasColumnName("guild_id");
+ b.Property("EphemeralConfirm")
+ .HasColumnType("boolean")
+ .HasColumnName("ephemeral_confirm");
+
b.Property("Use12HourTime")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")