-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Discord; | ||
using Discord.WebSocket; | ||
using QuoteBot.Data; | ||
using SimpleDiscordNet.Commands; | ||
|
||
namespace QuoteBot.Commands; | ||
|
||
public class RandomQuoteCommand { | ||
|
||
[SlashCommand("random-quote", "Display a random quote from this server.")] | ||
public async Task Execute(SocketSlashCommand cmd, DiscordSocketClient client) { | ||
if (cmd.Channel.GetChannelType() == ChannelType.DM) { | ||
await cmd.RespondWithEmbedAsync("Quote", "You can't do this in your DMs.", ResponseType.Error, ephemeral: false); | ||
return; | ||
} | ||
|
||
Quote? quote = Program.Storage.GetRandomQuote(cmd.GuildId!.Value); | ||
|
||
if (quote == null) { | ||
await cmd.RespondWithEmbedAsync("Quote", | ||
"This server has no quotes yet, quote someone by running /quote, /quote-user to by replying to a message and pinging me.", | ||
ResponseType.Error); | ||
return; | ||
} | ||
|
||
bool hasId = ulong.TryParse(quote.Quotee, out ulong quoteeId); | ||
IUser? quotee = hasId ? await client.GetUserAsync(quoteeId) : null; | ||
string quoteeDisplay = quotee?.Username ?? quote.Quotee; | ||
|
||
IUser? quoter = await client.GetUserAsync(quote.Quoter); | ||
string quoterDisplay = quoter?.Username ?? quote.Quoter.ToString(); | ||
|
||
EmbedBuilder embedBuilder = new(); | ||
embedBuilder.WithTitle(quoteeDisplay); | ||
embedBuilder.WithDescription($"\"{quote.Text}\""); | ||
embedBuilder.WithFooter("Quoted by " + quoterDisplay); | ||
embedBuilder.WithColor(Color.Green); | ||
|
||
await cmd.RespondAsync(embed: embedBuilder.Build()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters