Skip to content

Commit

Permalink
Add new banTrade command
Browse files Browse the repository at this point in the history
  • Loading branch information
bdawg1989 committed Jul 9, 2024
1 parent f8696ea commit 3a01c45
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions SysBot.Pokemon.Discord/Commands/Management/SudoModule.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using PKHeX.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace SysBot.Pokemon.Discord;
Expand Down Expand Up @@ -179,6 +181,47 @@ public async Task UnBlackListUsers([Remainder] string _)
await ReplyAsync("Done.").ConfigureAwait(false);
}

[Command("banTrade")]
[Alias("bant")]
[Summary("Bans a user from trading with a reason.")]
[RequireSudo]
public async Task BanTradeUser(ulong userNID, string? userName = null, [Remainder] string? banReason = null)
{
await Context.Message.DeleteAsync();
var dmChannel = await Context.User.CreateDMChannelAsync();
try
{
// Check if the ban reason is provided
if (string.IsNullOrWhiteSpace(banReason))
{
await dmChannel.SendMessageAsync("No reason was supplied. Please use the command as follows:\n.banTrade {NID} {optional: Name} {Reason}\nExample: .banTrade 123456789 Spamming trades");
return;
}

// Use a default name if none is provided
if (string.IsNullOrWhiteSpace(userName))
{
userName = "Unknown";
}

var me = SysCord<T>.Runner;
var hub = me.Hub;
var bannedUser = new RemoteControlAccess
{
ID = userNID,
Name = userName,
Comment = $"Banned by {Context.User.Username} on {DateTime.Now:yyyy.MM.dd-hh:mm:ss}. Reason: {banReason}"
};

hub.Config.TradeAbuse.BannedIDs.AddIfNew([bannedUser]);
await dmChannel.SendMessageAsync($"Done. User {userName} with NID {userNID} has been banned from trading.");
}
catch (Exception ex)
{
await dmChannel.SendMessageAsync($"An error occurred: {ex.Message}");
}
}

protected static IEnumerable<ulong> GetIDs(string content)
{
return content.Split([",", ", ", " "], StringSplitOptions.RemoveEmptyEntries)
Expand Down

0 comments on commit 3a01c45

Please sign in to comment.