Small update to the main Program.cs file

This commit is contained in:
Purplebored
2023-09-24 20:42:16 +02:00
parent 63ff45bfa3
commit e7abfa7b35

View File

@@ -10,7 +10,13 @@ using Microsoft.Extensions.Configuration;
class Program class Program
{ {
public static RevoltClient Client; public static RevoltClient Client;
public static async Task Start()
public static async Task Main(string[] args)
{
await StartAsync();
}
public static async Task StartAsync()
{ {
IConfiguration Configuration = new ConfigurationBuilder() IConfiguration Configuration = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory) .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
@@ -26,70 +32,82 @@ class Program
}); });
await Client.StartAsync(); await Client.StartAsync();
await Client.CurrentUser.ModifySelfAsync(statusText: new Option<string>("God please someone kill me."));
await Client.CurrentUser.ModifySelfAsync(statusType: new Option<UserStatusType>(UserStatusType.Focus));
CommandHandler CommandHandler = new CommandHandler(Client);
CommandHandler.LoadCommands();
await Task.Delay(-1);
}
static void Main(string[] args) // Modify user status
{ await Client.CurrentUser.ModifySelfAsync(
Start().GetAwaiter().GetResult(); statusText: new Option<string>("God please someone kill me."),
statusType: new Option<UserStatusType>(UserStatusType.Focus)
);
CommandHandler commandHandler = new CommandHandler(Client);
commandHandler.LoadCommands();
await Task.Delay(-1);
} }
} }
// CommandHandler // CommandHandler
public class CommandHandler public class CommandHandler
{ {
private readonly RevoltClient _client;
private readonly CommandService _service = new CommandService();
// Here you can change the prefix. Default is "?"
public const string Prefix = "?";
public CommandHandler(RevoltClient client) public CommandHandler(RevoltClient client)
{ {
Client = client; _client = client;
Client.OnMessageRecieved += Client_OnMessageRecieved; _client.OnMessageRecieved += Client_OnMessageReceived;
Service.OnCommandExecuted += Service_OnCommandExecuted; _service.OnCommandExecuted += Service_OnCommandExecuted;
} }
private RevoltClient Client;
private CommandService Service = new CommandService();
// Here you can change the prefix Default one is "?"
public const string Prefix = "?";
public async Task LoadCommands() public async Task LoadCommands()
{ {
await Service.AddModulesAsync(Assembly.GetEntryAssembly(), null); // Load commands from the entry assembly
await _service.AddModulesAsync(Assembly.GetEntryAssembly(), null);
} }
private void Client_OnMessageRecieved(Message msg)
private void Client_OnMessageReceived(Message msg)
{ {
UserMessage Message = msg as UserMessage; if (msg is not UserMessage userMessage || userMessage.Author.IsBot)
if (Message == null || Message.Author.IsBot)
return; return;
int argPos = 0; int argPos = 0;
if (!(Message.HasCharPrefix('?', ref argPos) || Message.HasMentionPrefix(Client.CurrentUser, ref argPos))) if (!(userMessage.HasCharPrefix('?', ref argPos) ||
userMessage.HasMentionPrefix(_client.CurrentUser, ref argPos)))
return; return;
CommandContext context = new CommandContext(Client, Message);
Service.ExecuteAsync(context, argPos, null); CommandContext context = new CommandContext(_client, userMessage);
_service.ExecuteAsync(context, argPos, null);
} }
private void Service_OnCommandExecuted(Optional<CommandInfo> commandinfo, CommandContext context, IResult result)
private void Service_OnCommandExecuted(Optional<CommandInfo> commandInfo, CommandContext context, IResult result)
{ {
if (result.IsSuccess) if (result.IsSuccess)
Console.WriteLine("Success command: " + commandinfo.Value.Name); {
Console.WriteLine("Success command: " + commandInfo.Value.Name);
}
else else
{ {
if (!commandinfo.HasValue) if (commandInfo.HasValue)
return; {
context.Channel.SendMessageAsync("Error: " + result.ErrorReason); context.Channel.SendMessageAsync("Error: " + result.ErrorReason);
} }
} }
// Only god and the dude behind RevoltSharp know what's going on here. }
// Only god and the developer of RevoltSharp know what's going on here.
} }
public class Commands : ModuleBase public class Commands : ModuleBase
{ {
// Help commands: // Help commands:
// Basic Help Command.
// Help command.
[Command("help")] [Command("help")]
public async Task Help() public async Task Help()
{ {
var helpMessage = "#### List of available commands:\n\n" + var helpMessage =
"#### List of available commands:\n\n" +
"#### Practical Commands: \n" + "#### Practical Commands: \n" +
"`?help` - Displays this command.\n" + "`?help` - Displays this command.\n" +
"`?source` - Links to the bots source code. \n" + "`?source` - Links to the bots source code. \n" +
@@ -99,18 +117,18 @@ public class Commands : ModuleBase
"`?calculate` {num} {+, - , / , * } {num} - A very simple calculator. \n" + "`?calculate` {num} {+, - , / , * } {num} - A very simple calculator. \n" +
"`?mod-help` - Displays a list of available mod commands. \n " + "`?mod-help` - Displays a list of available mod commands. \n " +
"`?ping` - tests the bot ping. \n" + "`?ping` - tests the bot ping. \n" +
"`?nsfw-help` - Sends a list of all aviable nsfw commands. \n " + "`?nsfw-help` - Sends a list of all available nsfw commands. \n " +
"#### Fun Commands: \n" + "#### Fun Commands: \n" +
"`?dice` - Rolls a random number between 1 and 6.\n" + "`?dice` - Rolls a random number between 1 and 6.\n" +
"`?say` - says what the user told it to say!. \n" + "`?say` - says what the user told it to say!. \n" +
"`?dm` - Just DMs the user Hi :3. \n" + "`?dm` - Just DMs the user Hi :3. \n" +
"`?rps {paper,rock,scissors}` - Simple Rock paper scissors game.\n" + "`?rps {paper,rock,scissors}` - Simple Rock paper scissors game.\n" +
"`?dogfact` - Gives a random dogfact using the Dogfact API!. \n" + "`?dogfact` - Gives a random dogfact using the Dogfact API!. \n" +
"`?catfact` - Gives a random Catfact using cat fact API (Currently somewhat bugged with the []. \n" + "`?catfact` - Gives a random Catfact using cat fact API (Currently somewhat bugged with the []). \n" +
"`?joke` - Very simple command just gives a joke using the Joke API. \n " + "`?joke` - Very simple command just gives a joke using the Joke API. \n " +
"`?flipcoin` - a Command so easy a child could do it. \n " + "`?flipcoin` - a Command so easy a child could do it. \n " +
"`?fact` - Gives a random useless fact. \n " + "`?fact` - Gives a random useless fact. \n " +
"`?urban + {word}` - uses the urban dictionary the search for the word. \n" + "`?urban + {word}` - uses the urban dictionary to search for the word. \n" +
"`?shitpost` - Sends a random shitpost. (The shitpost API is broken.) \n " + "`?shitpost` - Sends a random shitpost. (The shitpost API is broken.) \n " +
"`?cat` - Cat :3 \n " + "`?cat` - Cat :3 \n " +
"`?neko` - Neko command \n " + "`?neko` - Neko command \n " +
@@ -120,14 +138,21 @@ public class Commands : ModuleBase
"`?avatar` - Sends the user Avatar (Beta) \n "; "`?avatar` - Sends the user Avatar (Beta) \n ";
await ReplyAsync(helpMessage); await ReplyAsync(helpMessage);
} }
// End of the Help command.
// Mod Help command // Mod Help command
[Command("mod-help")] [Command("mod-help")]
public async Task modhelp() public async Task ModHelp()
{ {
await ReplyAsync( string helpMessage =
"## List Of Available mod commands. \n `?kick {Mention}` - Kicks the user \n `?ban {mentions}` - Bans the User \n `?unban {mention}` - Unbans the user. \n"); "## List Of Available mod commands. \n" +
"`?kick {Mention}` - Kicks the user \n" +
"`?ban {mentions}` - Bans the User \n" +
"`?unban {mention}` - Unbans the user. \n";
await ReplyAsync(helpMessage);
} }
// End of the mod-Help command
// NSFW Help command: // NSFW Help command:
[Command("nsfw-help")] [Command("nsfw-help")]
@@ -135,42 +160,54 @@ public class Commands : ModuleBase
{ {
await ReplyAsync("### Here are all the available NSFW commands: \n `?r34 {search}` - Searches rule34.xxx \n `?hentai` - Grabs a random hentai image \n "); await ReplyAsync("### Here are all the available NSFW commands: \n `?r34 {search}` - Searches rule34.xxx \n `?hentai` - Grabs a random hentai image \n ");
} }
// End of the help command Section // End of the NSFW-HELP command
// End of the help commands
// Dm Commands (commands that dm the user in some way.): // Dm Commands (commands that dm the user in some way.):
// Invite Command - Sends a invite in the DM // Invite Command - Sends a invite in the DM
[Command("invite")] [Command("invite")]
public async Task Invite() public async Task Invite()
{ {
DMChannel DM = await Context.User.GetDMChannelAsync(); DMChannel DM = await Context.User.GetDMChannelAsync();
if (DM == null) if (DM == null)
{ {
await ReplyAsync("Could not open DM :( wich means no invite :((("); await ReplyAsync("Could not open DM :(");
return; return;
} }
await DM.SendMessageAsync("## Invite me! \n" + await DM.SendMessageAsync(
"If you on app.haydar.dev use this link: \n" + "## Invite me! \n" +
"If you're on app.haydar.dev, use this link: \n" +
"https://app.haydar.dev/bot/01HA55V3K8B26T87TBKMZMWRKJ \n" + "https://app.haydar.dev/bot/01HA55V3K8B26T87TBKMZMWRKJ \n" +
"but if you on nightly.haydar.dev use this link \n" + "But if you're on nightly.haydar.dev, use this link: \n" +
"https://nightly.haydar.dev/bot/01HA55V3K8B26T87TBKMZMWRKJ \n" + "https://nightly.haydar.dev/bot/01HA55V3K8B26T87TBKMZMWRKJ \n" +
"If you find any bugs report them to the bots creator. Thank you bye!"); "If you find any bugs, report them to the bot's creator. Thank you and bye!"
);
} }
// End of the Invite command
// The Debug command.
[Command("debug")] [Command("debug")]
public async Task Debug() public async Task Debug()
{ {
DMChannel DM = await Context.User.GetDMChannelAsync(); DMChannel DM = await Context.User.GetDMChannelAsync();
if (DM == null) if (DM == null)
{ {
await ReplyAsync("Your code is so messed up that even DMs are broken :skull: wow"); await ReplyAsync("Your code is so messed up that even DMs are broken :skull: wow");
return; return;
} }
try try
{ {
// Send initial message // Send initial message
await DM.SendMessageAsync("DMs work if you received this message."); await DM.SendMessageAsync("DMs work if you received this message.");
await DM.SendMessageAsync("-----"); await DM.SendMessageAsync("-----");
await DM.SendMessageAsync("You should recive the ping of the bot and a shitpost"); await DM.SendMessageAsync("You should receive the ping of the bot and a shitpost");
// Ping part // Ping part
var stopwatch = new Stopwatch(); var stopwatch = new Stopwatch();
stopwatch.Start(); stopwatch.Start();
@@ -179,17 +216,18 @@ public class Commands : ModuleBase
var latency = stopwatch.ElapsedMilliseconds; var latency = stopwatch.ElapsedMilliseconds;
await DM.SendMessageAsync($"The ping is: {latency}ms"); await DM.SendMessageAsync($"The ping is: {latency}ms");
await DM.SendMessageAsync("-----"); await DM.SendMessageAsync("-----");
// Shitpost part // Shitpost part
await SendRandomMeme(DM); await SendRandomMeme(DM);
await DM.SendMessageAsync("If you saw a Shitpost and the ping of the bot everything should work correctly."); await DM.SendMessageAsync("If you saw a Shitpost and the ping of the bot everything should work correctly.");
} }
catch (Exception ex) catch (Exception ex)
{ {
await DM.SendMessageAsync($"An error occurred: {ex.Message}"); await DM.SendMessageAsync($"An error occurred: {ex.Message}");
} }
} }
// Shitpost Logic
// The Shitpost Part.
private async Task SendRandomMeme(DMChannel DM) private async Task SendRandomMeme(DMChannel DM)
{ {
const string apiUrl = "https://api.thedailyshitpost.net/random"; const string apiUrl = "https://api.thedailyshitpost.net/random";
@@ -221,7 +259,9 @@ public class Commands : ModuleBase
} }
} }
} }
// End of the Debug command. // End of the Debug command.
// End of DM commands. // End of DM commands.
// Debug commands. // Debug commands.
@@ -232,6 +272,7 @@ public class Commands : ModuleBase
{ {
await ReplyAsync("Ig it works :tm:"); await ReplyAsync("Ig it works :tm:");
} }
// Ping command. // Ping command.
[Command("ping")] [Command("ping")]
public async Task PingCommand() public async Task PingCommand()
@@ -246,9 +287,11 @@ public class Commands : ModuleBase
await ReplyAsync($"Pong! (Latency: {latency}ms)"); await ReplyAsync($"Pong! (Latency: {latency}ms)");
} }
// End of the Debug commands. // End of the Debug commands.
// Fun commands: // Fun commands:
// Gif command // Gif command
[Command("gif")] [Command("gif")]
public async Task GifCommand([Remainder] string keyword) public async Task GifCommand([Remainder] string keyword)
@@ -287,8 +330,9 @@ public class Commands : ModuleBase
} }
} }
} }
// End of the GIF commands
// A Rock paper Scicors command. // A Rock paper Scissors command.
[Command("rps")] [Command("rps")]
public async Task Rps([Remainder] string userChoice = null) public async Task Rps([Remainder] string userChoice = null)
{ {
@@ -304,7 +348,7 @@ public class Commands : ModuleBase
userChoice = userChoice.ToLower(); userChoice = userChoice.ToLower();
if (Array.Exists(options, option => option == userChoice)) if (options.Contains(userChoice))
{ {
if (userChoice == botChoice) if (userChoice == botChoice)
{ {
@@ -326,21 +370,24 @@ public class Commands : ModuleBase
await ReplyAsync($"Invalid choice. Please choose from: {string.Join(", ", options)}"); await ReplyAsync($"Invalid choice. Please choose from: {string.Join(", ", options)}");
} }
} }
// End of the Rock paper scicors command
// Roll command roles a random number between 1 - 6 (Perfect for bets :troll") // Dice command rolls a random number between 1 - 6 (Perfect for bets :troll")
[Command("dice")] [Command("dice")]
public async Task dice() public async Task Dice()
{ {
var random = new Random(); var random = new Random();
var result = random.Next(1, 7); var result = random.Next(1, 7);
await ReplyAsync($"You rolled a {result}!"); await ReplyAsync($"You rolled a {result}!");
} }
// End of the Dice command
// Very simple very say command. // Very simple say command.
private List<string> blacklist = new List<string> private List<string> blacklist = new List<string>
{ {
"nigga", "nigger", "n i g g a", "fuck", "shit", "piss", "cunt", "dick", "fag", "faggot", "kys", "ky$", // Blacklist for the say command "nigga", "nigger", "n i g g a", "fuck", "shit", "piss",
}; "cunt", "dick", "fag", "faggot", "kys", "ky$",
};
[Command("say")] [Command("say")]
public async Task Say([Remainder] string text) public async Task Say([Remainder] string text)
@@ -356,19 +403,12 @@ public class Commands : ModuleBase
} }
await ReplyAsync($"{user} said: {text}"); await ReplyAsync($"{user} said: {text}");
} }
// End of the Say command
// Haydar. // The coinflip command.
[Command("miau")] [Command("coinflip")]
public async Task miau() public async Task Coinflip()
{
await ReplyAsync("<@01H4H8M7E20HJAD6DXKDMXVKXF> Miau???");
}
// The flip a coin command.
[Command("flipcoin")]
public async Task FlipCoin()
{ {
Random random = new Random(); Random random = new Random();
int result = random.Next(2); int result = random.Next(2);
@@ -377,7 +417,10 @@ public class Commands : ModuleBase
await ReplyAsync($"It's {side}!"); await ReplyAsync($"It's {side}!");
} }
// End of the coinflip command.
// End of the Fun commands. // End of the Fun commands.
// Api commands // Api commands
// Advice command. // Advice command.
@@ -385,6 +428,8 @@ public class Commands : ModuleBase
public async Task Advice() public async Task Advice()
{ {
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{
try
{ {
string apiUrl = "https://api.adviceslip.com/advice"; string apiUrl = "https://api.adviceslip.com/advice";
HttpResponseMessage response = await client.GetAsync(apiUrl); HttpResponseMessage response = await client.GetAsync(apiUrl);
@@ -394,7 +439,7 @@ public class Commands : ModuleBase
string adviceJson = await response.Content.ReadAsStringAsync(); string adviceJson = await response.Content.ReadAsStringAsync();
JObject adviceObject = JObject.Parse(adviceJson); JObject adviceObject = JObject.Parse(adviceJson);
string advice = adviceObject["slip"]["advice"]?.ToString(); string advice = adviceObject["slip"]?["advice"]?.ToString();
if (!string.IsNullOrEmpty(advice)) if (!string.IsNullOrEmpty(advice))
{ {
@@ -410,12 +455,21 @@ public class Commands : ModuleBase
await ReplyAsync("Sorry, I couldn't fetch advice at the moment. Please try again later."); await ReplyAsync("Sorry, I couldn't fetch advice at the moment. Please try again later.");
} }
} }
catch (Exception ex)
{
await ReplyAsync($"An error occurred: {ex.Message}");
} }
}
}
// End of the Advice command
// Dog fact command very simple very fun // Dog fact command very simple very fun
[Command("dogfact")] [Command("dogfact")]
public async Task DogFact() public async Task DogFact()
{ {
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{
try
{ {
string apiUrl = "http://dog-api.kinduff.com/api/facts"; string apiUrl = "http://dog-api.kinduff.com/api/facts";
HttpResponseMessage response = await client.GetAsync(apiUrl); HttpResponseMessage response = await client.GetAsync(apiUrl);
@@ -443,12 +497,21 @@ public class Commands : ModuleBase
await ReplyAsync("Sorry, I couldn't fetch a dog fact at the moment. Please try again later."); await ReplyAsync("Sorry, I couldn't fetch a dog fact at the moment. Please try again later.");
} }
} }
catch (Exception ex)
{
await ReplyAsync($"An error occurred: {ex.Message}");
} }
}
}
// End of the Dogfact command
// Cat fact command very simple very fun // Cat fact command very simple very fun
[Command("catfact")] [Command("catfact")]
public async Task CatFact() public async Task CatFact()
{ {
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{
try
{ {
string apiUrl = "http://meowfacts.herokuapp.com/"; string apiUrl = "http://meowfacts.herokuapp.com/";
HttpResponseMessage response = await client.GetAsync(apiUrl); HttpResponseMessage response = await client.GetAsync(apiUrl);
@@ -473,12 +536,21 @@ public class Commands : ModuleBase
await ReplyAsync("Sorry, I couldn't fetch a cat fact at the moment. Please try again later."); await ReplyAsync("Sorry, I couldn't fetch a cat fact at the moment. Please try again later.");
} }
} }
catch (Exception ex)
{
await ReplyAsync($"An error occurred: {ex.Message}");
} }
}
}
// End of the Cat fact command
// Joke command // Joke command
[Command("joke")] [Command("joke")]
public async Task Joke() public async Task Joke()
{ {
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{
try
{ {
string apiUrl = "https://v2.jokeapi.dev/joke/Any?type=twopart"; string apiUrl = "https://v2.jokeapi.dev/joke/Any?type=twopart";
HttpResponseMessage response = await client.GetAsync(apiUrl); HttpResponseMessage response = await client.GetAsync(apiUrl);
@@ -505,12 +577,21 @@ public class Commands : ModuleBase
await ReplyAsync("Sorry, I couldn't fetch a joke at the moment. Please try again later."); await ReplyAsync("Sorry, I couldn't fetch a joke at the moment. Please try again later.");
} }
} }
catch (Exception ex)
{
await ReplyAsync($"An error occurred: {ex.Message}");
} }
}
}
// End of the Joke command
// Simple quote command // Simple quote command
[Command("quote")] [Command("quote")]
public async Task Quote() public async Task Quote()
{ {
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{
try
{ {
string apiUrl = "https://api.quotable.io/random"; string apiUrl = "https://api.quotable.io/random";
HttpResponseMessage response = await client.GetAsync(apiUrl); HttpResponseMessage response = await client.GetAsync(apiUrl);
@@ -530,12 +611,21 @@ public class Commands : ModuleBase
await ReplyAsync("Sorry, I couldn't fetch a quote at the moment. Please try again later."); await ReplyAsync("Sorry, I couldn't fetch a quote at the moment. Please try again later.");
} }
} }
catch (Exception ex)
{
await ReplyAsync($"An error occurred: {ex.Message}");
} }
}
}
// End of the qoute command
// Fact command // Fact command
[Command("fact")] [Command("fact")]
public async Task Fact() public async Task Fact()
{ {
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{
try
{ {
string apiUrl = "https://uselessfacts.jsph.pl/random.json?language=en"; string apiUrl = "https://uselessfacts.jsph.pl/random.json?language=en";
HttpResponseMessage response = await client.GetAsync(apiUrl); HttpResponseMessage response = await client.GetAsync(apiUrl);
@@ -553,8 +643,15 @@ public class Commands : ModuleBase
await ReplyAsync("Sorry, I couldn't fetch a fact at the moment. Please try again later."); await ReplyAsync("Sorry, I couldn't fetch a fact at the moment. Please try again later.");
} }
} }
catch (Exception ex)
{
await ReplyAsync($"An error occurred: {ex.Message}");
} }
// Urban Dictionary }
}
// End of the fact command
// Urban command
[Command("urban")] [Command("urban")]
public async Task Urban([Remainder] string term) public async Task Urban([Remainder] string term)
{ {
@@ -570,9 +667,14 @@ public class Commands : ModuleBase
if (urbanObject.list.Count > 0) if (urbanObject.list.Count > 0)
{ {
string definition = urbanObject.list[0].definition; int maxDefinitions = 3;
await ReplyAsync($"**Term:** {term}\n**Definition:** {definition}"); for (int i = 0; i < Math.Min(maxDefinitions, urbanObject.list.Count); i++)
{
string definition = urbanObject.list[i].definition;
string formattedMessage = $"```\nTerm: {term}\nDefinition {i + 1}:\n{definition}\n```";
await ReplyAsync(formattedMessage);
}
} }
else else
{ {
@@ -585,11 +687,15 @@ public class Commands : ModuleBase
} }
} }
} }
// End of the Urban command
// Shitpost command // Shitpost command
[Command("shitpost")] [Command("shitpost")]
public async Task shitpost() public async Task Shitpost()
{ {
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{
try
{ {
string apiUrl = "https://api.thedailyshitpost.net/random"; string apiUrl = "https://api.thedailyshitpost.net/random";
HttpResponseMessage response = await client.GetAsync(apiUrl); HttpResponseMessage response = await client.GetAsync(apiUrl);
@@ -602,19 +708,28 @@ public class Commands : ModuleBase
string title = memeObject.title; string title = memeObject.title;
string imageUrl = memeObject.url; string imageUrl = memeObject.url;
await ReplyAsync($"{imageUrl}"); await ReplyAsync(imageUrl);
} }
else else
{ {
await ReplyAsync("Sorry, I couldn't fetch a meme at the moment. Please try again later."); await ReplyAsync("Sorry, I couldn't fetch a meme at the moment. Please try again later.");
} }
} }
catch (Exception ex)
{
await ReplyAsync($"An error occurred: {ex.Message}");
} }
// Cat. }
}
// End of the shitpost command
// Cat command.
[Command("cat")] [Command("cat")]
public async Task Cat() public async Task Cat()
{ {
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
{
try
{ {
string apiUrl = "https://api.thecatapi.com/v1/images/search"; string apiUrl = "https://api.thecatapi.com/v1/images/search";
HttpResponseMessage response = await client.GetAsync(apiUrl); HttpResponseMessage response = await client.GetAsync(apiUrl);
@@ -624,8 +739,10 @@ public class Commands : ModuleBase
string catJson = await response.Content.ReadAsStringAsync(); string catJson = await response.Content.ReadAsStringAsync();
dynamic catObject = Newtonsoft.Json.JsonConvert.DeserializeObject(catJson); dynamic catObject = Newtonsoft.Json.JsonConvert.DeserializeObject(catJson);
string imageUrl = catObject[0].url; string imageUrl = catObject[0]?.url;
if (!string.IsNullOrEmpty(imageUrl))
{
await ReplyAsync(imageUrl); await ReplyAsync(imageUrl);
} }
else else
@@ -633,7 +750,19 @@ public class Commands : ModuleBase
await ReplyAsync("Sorry, I couldn't fetch a cat image at the moment. Please try again later."); await ReplyAsync("Sorry, I couldn't fetch a cat image at the moment. Please try again later.");
} }
} }
else
{
await ReplyAsync("Sorry, I couldn't fetch a cat image at the moment. Please try again later.");
} }
}
catch (Exception ex)
{
await ReplyAsync($"An error occurred: {ex.Message}");
}
}
}
// End of the cat command
// Neko command // Neko command
[Command("neko")] [Command("neko")]
public async Task Neko() public async Task Neko()
@@ -676,13 +805,16 @@ public class Commands : ModuleBase
// End of neko command // End of neko command
// The End of the API commands. // The End of the API commands.
// Misc Commands: // Misc Commands:
// Give the credits of the bot // Give the credits of the bot
[Command("credits")] [Command("credits")]
public async Task Credits() public async Task Credits()
{ {
await ReplyAsync("This bot is made using revoltsharp by Purplebored known as Kniaż Jarema on nightly"); await ReplyAsync("This bot is made using revoltsharp by Purplebored known as Kniaż Jarema on nightly");
} }
// End of the Credits command
// Avatar command // Avatar command
[Command("avatar")] [Command("avatar")]
@@ -693,7 +825,7 @@ public class Commands : ModuleBase
await Context.Channel.SendMessageAsync($"Your avatar: {avatarUrl}"); await Context.Channel.SendMessageAsync($"Your avatar: {avatarUrl}");
} }
// End of the misc commands // End of the Avatar command
// Calculate command // Calculate command
[Command("calculate")] [Command("calculate")]
@@ -738,28 +870,38 @@ public class Commands : ModuleBase
await ReplyAsync($"Result: {result}"); await ReplyAsync($"Result: {result}");
} }
// End of the Calculat command.
// Moderation commands. from Darkly Bot // End of the misc commands
// Stuff neded to make these commands work.
// Mod Commands
// Stuff needed to make these commands work.
private string RemoveMention(string mention) private string RemoveMention(string mention)
{ {
return mention.Replace("<@", "").Replace(">", ""); return mention.Replace("<@", "").Replace(">", "");
} }
private RevoltClient Client; private RevoltClient Client;
// Stats command // Stats command
[Command("stats")] [Command("stats")]
public async Task GetStats() public async Task GetStats()
{
try
{ {
IReadOnlyCollection<ServerMember> result1 = await Context.Server.GetMembersAsync(); IReadOnlyCollection<ServerMember> result1 = await Context.Server.GetMembersAsync();
int num2 = 0; int num2 = result1.Count;
foreach (ServerMember serverMember in result1)
++num2;
IReadOnlyCollection<ServerMember> result2 = await Context.Server.GetMembersAsync(true); IReadOnlyCollection<ServerMember> result2 = await Context.Server.GetMembersAsync(true);
int num3 = 0; int num3 = result2.Count;
foreach (ServerMember serverMember in result2) await ReplyAsync($"### Stats:\n\n### Member count: {num2}\n### Online member count: {num3}\n");
++num3;
await ReplyAsync($"### Stats:\n \n ### Member count: {num2}\n ### Online member count: {num3}\n");
} }
catch (Exception ex)
{
await ReplyAsync($"An error occurred: {ex.Message}");
}
}
// Ban Command // Ban Command
[Command("ban")] [Command("ban")]
public async Task BanUser([Remainder] string args) public async Task BanUser([Remainder] string args)
@@ -768,13 +910,14 @@ public class Commands : ModuleBase
{ {
string userId = RemoveMention(args); string userId = RemoveMention(args);
await Context.Server.BanMemberAsync(userId, "Banned via command."); await Context.Server.BanMemberAsync(userId, "Banned via command.");
await ReplyAsync("### Ban\n whomp whomp."); await ReplyAsync("### Ban\nwhomp whomp.");
} }
catch catch
{ {
await ReplyAsync("### ERROR \n Invalid Mention or Bot Perms."); await ReplyAsync("### ERROR\nInvalid Mention or Bot Permissions.");
} }
} }
// Unban Command // Unban Command
[Command("unban")] [Command("unban")]
public async Task UnbanUser([Remainder] string args) public async Task UnbanUser([Remainder] string args)
@@ -783,13 +926,14 @@ public class Commands : ModuleBase
{ {
string userId = RemoveMention(args); string userId = RemoveMention(args);
await Context.Server.UnBanMemberAsync(userId); await Context.Server.UnBanMemberAsync(userId);
await ReplyAsync("### Unbanned \n Very sadly a mod had a change of his heart."); await ReplyAsync("### Unbanned\nVery sadly a mod had a change of heart.");
} }
catch catch
{ {
await ReplyAsync("### ERROR \n Invalid Mention or Bot Perms."); await ReplyAsync("### ERROR\nInvalid Mention or Bot Permissions.");
} }
} }
// Kick Command // Kick Command
[Command("kick")] [Command("kick")]
public async Task KickUser([Remainder] string args) public async Task KickUser([Remainder] string args)
@@ -798,17 +942,23 @@ public class Commands : ModuleBase
{ {
string userId = RemoveMention(args); string userId = RemoveMention(args);
await Context.Server.KickMemberAsync(userId); await Context.Server.KickMemberAsync(userId);
await ReplyAsync("### Kicked \n And he gone."); await ReplyAsync("### Kicked\nAnd he's gone.");
} }
catch catch
{ {
await ReplyAsync("### ERROR \\n Invalid Mention or Bot Perms."); await ReplyAsync("### ERROR\nInvalid Mention or Bot Permissions.");
} }
} }
// End of mod commands
// NSFW COMMANDS // NSFW COMMANDS
// R34 command. // R34 command.
[Command("r34")] [Command("r34")]
public async Task ExampleCommand([Remainder] string query = null) public async Task ExampleCommand([Remainder] string query = null)
{
try
{ {
if (string.IsNullOrWhiteSpace(query)) if (string.IsNullOrWhiteSpace(query))
{ {
@@ -818,8 +968,7 @@ public class Commands : ModuleBase
if (!(Context.Channel is TextChannel textChannel) || !textChannel.IsNsfw) if (!(Context.Channel is TextChannel textChannel) || !textChannel.IsNsfw)
{ {
await Context.Channel.SendMessageAsync( await Context.Channel.SendMessageAsync("This command is only allowed in NSFW channels. So go to a NSFW channel to get your NSFW smh");
"This command is only allowed in NSFW channels. So go to a NSFW channel to get your NSFW smh");
return; return;
} }
@@ -846,19 +995,25 @@ public class Commands : ModuleBase
} }
else else
{ {
await Context.Channel.SendMessageAsync( await Context.Channel.SendMessageAsync("Sorry, I couldn't fetch an image at the moment. Please try again later.");
"Sorry, I couldn't fetch an image at the moment. Please try again later.");
} }
} }
} }
catch (Exception ex)
{
await Context.Channel.SendMessageAsync($"An error occurred: {ex.Message}");
}
}
// Hentai command. // Hentai command.
[Command("hentai")] [Command("hentai")]
public async Task hentai() public async Task Hentai()
{
try
{ {
if (!(Context.Channel is TextChannel textChannel) || !textChannel.IsNsfw) if (!(Context.Channel is TextChannel textChannel) || !textChannel.IsNsfw)
{ {
await Context.Channel.SendMessageAsync( await Context.Channel.SendMessageAsync("This command is only allowed in NSFW channels. So go to a NSFW channel to get your NSFW smh");
"This command is only allowed in NSFW channels. So go to a NSFW channel to get your NSFW smh");
return; return;
} }
using (HttpClient client = new HttpClient()) using (HttpClient client = new HttpClient())
@@ -881,4 +1036,11 @@ public class Commands : ModuleBase
} }
} }
} }
catch (Exception ex)
{
await Context.Channel.SendMessageAsync($"An error occurred: {ex.Message}");
}
}
// End of NSFW commands
// End of the Bot
} }