Skip to content

Commit

Permalink
Add /status set and /status clear
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Aug 27, 2023
1 parent da8dfb4 commit b75264e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
51 changes: 51 additions & 0 deletions Commands/InteractionCommands/StatusInteractions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace Cliptok.Commands.InteractionCommands
{
internal class StatusInteractions : ApplicationCommandModule
{
[SlashCommandGroup("status", "Status commands")]
[SlashRequireHomeserverPerm(ServerPermLevel.TrialModerator)]
[SlashCommandPermissions(Permissions.ModerateMembers)]

public class StatusSlashCommands
{

[SlashCommand("set", "Set Cliptoks status.", defaultPermission: false)]
public async Task StatusSetCommand(
InteractionContext ctx,
[Option("text", "The text to use for the status.")] string statusText,
[Choice("Custom", (long)ActivityType.Custom)]
[Choice("Playing", (long)ActivityType.Playing)]
[Choice("Streaming", (long)ActivityType.Streaming)]
[Choice("Listening to", (long)ActivityType.ListeningTo)]
[Choice("Watching", (long)ActivityType.Watching)]
[Choice("Competing", (long)ActivityType.Competing)]
[Option("type", "Defaults to custom. The type of status to use.")] long statusType = (long)ActivityType.Custom
)
{
if (statusText.Length > 128)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Status messages must be less than 128 characters.");
}

await Program.db.StringSetAsync("config:status", statusText);
await Program.db.StringSetAsync("config:status_type", statusType);

await ctx.Client.UpdateStatusAsync(new DiscordActivity(statusText, (ActivityType)statusType));

await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Status has been updated!\nType: `{((ActivityType)statusType).ToString()}`\nText: `{statusText}`");
}

[SlashCommand("clear", "Clear Cliptoks status.", defaultPermission: false)]
public async Task StatusClearCommand(InteractionContext ctx)
{
await Program.db.KeyDeleteAsync("config:status");
await Program.db.KeyDeleteAsync("config:status_type");

await ctx.Client.UpdateStatusAsync(new DiscordActivity());

await ctx.RespondAsync($"{Program.cfgjson.Emoji.Deleted} Status has been cleared!");
}

}
}
}
16 changes: 14 additions & 2 deletions Events/ReadyEvent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using DSharpPlus.EventArgs;
using static Cliptok.Program;
using static Cliptok.Program;

namespace Cliptok.Events
{
Expand All @@ -17,6 +16,19 @@ public static async Task OnReady(DiscordClient client, SessionReadyEventArgs _)
client.Logger.LogDebug("Successfully initalised malicious invite list with {count} servers.", fetchResult.Count);
}

if (db.KeyExists("config:status") && db.KeyExists("config:status_type")) {
var statusText = await db.StringGetAsync("config:status");
var statusType = await db.StringGetAsync("config:status_type");

try
{
await client.UpdateStatusAsync(new DiscordActivity(statusText, (ActivityType)(long)statusType));
} catch (Exception ex)
{
client.Logger.LogError(ex, "Error updating status to {status}", statusText);
}
}

client.Logger.LogInformation(CliptokEventID, "Logged in as {user}", $"{DiscordHelpers.UniqueUsername(client.CurrentUser)}");
}

Expand Down

0 comments on commit b75264e

Please sign in to comment.