1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-05-04 21:16:29 +03:00
This commit is contained in:
l1ttleO 2021-12-07 23:27:27 +05:00
parent 3fa19a4794
commit 8644f70b14
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
7 changed files with 158 additions and 37 deletions

View file

@ -0,0 +1,26 @@
using Discord;
using Discord.Commands;
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
namespace Boyfriend.Commands;
public class BanModule : ModuleBase<SocketCommandContext> {
[Command("ban")]
[Summary("Банит пользователя")]
[Alias("бан")]
public async Task Run(IUser toBan, TimeSpan duration, [Remainder]string reason)
=> await BanUser(Context.Guild, Context.User, toBan, duration, reason);
public async void BanUser(IGuild guild, IUser author, IUser toBan, TimeSpan duration, string reason = "") {
var authorMention = author.Mention;
await toBan.SendMessageAsync("Тебя забанил " + authorMention + " за " + reason);
await guild.AddBanAsync(toBan, 0, reason);
await guild.GetSystemChannelAsync().Result.SendMessageAsync(authorMention + " банит " + toBan.Mention + " за "
+ reason);
var banTimer = new System.Timers.Timer(duration.Milliseconds);
banTimer.Elapsed += UnbanModule.UnbanUser(guild, author, toBan, "Время наказания истекло").;
banTimer.Start();
}
}

View file

@ -1,4 +1,6 @@
using Discord.Commands;
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
namespace Boyfriend.Commands;

View file

@ -0,0 +1,23 @@
using Discord;
using Discord.Commands;
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
namespace Boyfriend.Commands;
public class UnbanModule : ModuleBase<SocketCommandContext> {
[Command("unban")]
[Summary("Возвращает пользователя из бана")]
[Alias("разбан")]
public async Task Run(IUser toBan, TimeSpan duration, [Remainder]string reason)
=> await UnbanUser(Context.Guild, Context.User, toBan, reason);
public async Task UnbanUser(IGuild guild, IUser author, IUser toBan, string reason = "") {
var authorMention = author.Mention;
await toBan.SendMessageAsync("Тебя разбанил " + authorMention + " за " + reason);
await guild.RemoveBanAsync(toBan);
await guild.GetSystemChannelAsync().Result.SendMessageAsync(authorMention + " возвращает из бана "
+ toBan.Mention + " за " + reason);
}
}