1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-05-04 21:16:29 +03:00

a ton of stuff

This commit is contained in:
l1ttleO 2021-12-10 16:25:29 +05:00
parent 8644f70b14
commit 382add19a3
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
13 changed files with 304 additions and 67 deletions

View file

@ -1,7 +1,9 @@
using Discord;
using Discord.Commands;
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
// ReSharper disable ClassNeverInstantiated.Global
namespace Boyfriend.Commands;
@ -10,17 +12,25 @@ 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);
[RequireBotPermission(GuildPermission.BanMembers)]
[RequireUserPermission(GuildPermission.BanMembers)]
public Task Run(string user, TimeSpan duration, [Remainder]string reason) {
var toBan = Utils.ParseUser(user).Result;
BanUser(Context.Guild, Context.User, toBan, duration, reason);
return Task.CompletedTask;
}
public async void BanUser(IGuild guild, IUser author, IUser toBan, TimeSpan duration, string reason = "") {
public static 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();
await Utils.SendDirectMessage(toBan, $"Тебя забанил {author.Mention} на сервере {guild.Name} за `{reason}`");
var guildBanMessage = $"({author.Username}#{author.Discriminator}) {reason}";
await guild.AddBanAsync(toBan, 0, guildBanMessage);
var notification = $"{authorMention} банит {toBan.Mention} за {Utils.WrapInline(reason)}";
await Utils.SilentSendAsync(guild.GetSystemChannelAsync().Result, notification);
await Utils.SilentSendAsync(Utils.GetAdminLogChannel(), notification);
var task = new Task(() => UnbanModule.UnbanUser(guild, guild.GetCurrentUserAsync().Result, toBan,
"Время наказания истекло"));
await Utils.StartDelayed(task, duration, () => guild.GetBanAsync(toBan).Result != null);
}
}

View file

@ -0,0 +1,34 @@
using Discord;
using Discord.Commands;
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
// ReSharper disable ClassNeverInstantiated.Global
namespace Boyfriend.Commands;
public class ClearModule : ModuleBase<SocketCommandContext> {
[Command("clear")]
[Summary("Удаляет указанное количество сообщений")]
[Alias("очистить")]
[RequireBotPermission(GuildPermission.ManageMessages)]
[RequireUserPermission(GuildPermission.ManageMessages)]
public async Task Run(int toDelete) {
if (Context.Channel is not ITextChannel channel) return;
switch (toDelete) {
case < 1:
throw new ArgumentException("toDelete is less than 1.");
case > 200:
throw new ArgumentException("toDelete is more than 200.");
default: {
var messages = await channel.GetMessagesAsync(toDelete + 1).FlattenAsync();
await channel.DeleteMessagesAsync(messages);
await Utils.GetAdminLogChannel().SendMessageAsync(
$"{Context.User.Mention} удаляет {toDelete + 1} сообщений в канале " +
$"{Utils.MentionChannel(Context.Channel.Id)}");
break;
}
}
}
}

View file

@ -0,0 +1,34 @@
using Discord;
using Discord.Commands;
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
// ReSharper disable ClassNeverInstantiated.Global
namespace Boyfriend.Commands;
public class KickModule : ModuleBase<SocketCommandContext> {
[Command("kick")]
[Summary("Выгоняет пользователя")]
[Alias("кик")]
[RequireBotPermission(GuildPermission.KickMembers)]
[RequireUserPermission(GuildPermission.KickMembers)]
public Task Run(string user, [Remainder]string reason) {
var toKick = Utils.ParseMember(Context.Guild, user).Result;
KickMember(Context.Guild, Context.User, toKick, reason);
return Task.CompletedTask;
}
private static async void KickMember(IGuild guild, IUser author, IGuildUser toKick, string reason) {
var authorMention = author.Mention;
await Utils.SendDirectMessage(toKick, $"Тебя кикнул {authorMention} на сервере {guild.Name} за " +
$"{Utils.WrapInline(reason)}");
var guildKickMessage = $"({author.Username}#{author.Discriminator}) {reason}";
await toKick.KickAsync(guildKickMessage);
var notification = $"{authorMention} выгоняет {toKick.Mention} за {Utils.WrapInline(reason)}";
await Utils.SilentSendAsync(guild.GetSystemChannelAsync().Result, notification);
await Utils.SilentSendAsync(Utils.GetAdminLogChannel(), notification);
}
}

View file

@ -0,0 +1,35 @@
using Discord;
using Discord.Commands;
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
// ReSharper disable ClassNeverInstantiated.Global
namespace Boyfriend.Commands;
public class MuteModule : ModuleBase<SocketCommandContext> {
[Command("mute")]
[Summary("Глушит пользователя")]
[Alias("мут")]
[RequireBotPermission(GuildPermission.ManageRoles)]
[RequireUserPermission(GuildPermission.ManageMessages)]
public Task Run(string user, TimeSpan duration, [Remainder]string reason) {
var toMute = Utils.ParseMember(Context.Guild, user).Result;
MuteMember(Context.Guild, Context.User, toMute, duration, reason);
return Task.CompletedTask;
}
private static async void MuteMember(IGuild guild, IMentionable author, IGuildUser toMute, TimeSpan duration,
string reason) {
var authorMention = author.Mention;
var role = Utils.GetMuteRole(guild);
await toMute.AddRoleAsync(role);
var notification = $"{authorMention} глушит {toMute.Mention} за {Utils.WrapInline(reason)}";
await Utils.SilentSendAsync(guild.GetSystemChannelAsync().Result, notification);
await Utils.SilentSendAsync(Utils.GetAdminLogChannel(), notification);
var task = new Task(() => UnmuteModule.UnmuteMember(guild, guild.GetCurrentUserAsync().Result, toMute,
"Время наказания истекло"));
await Utils.StartDelayed(task, duration, () => toMute.RoleIds.Any(x => x == role.Id));
}
}

View file

@ -10,5 +10,5 @@ public class PingModule : ModuleBase<SocketCommandContext> {
[Summary("Измеряет время обработки REST-запроса")]
[Alias("пинг")]
public async Task Run()
=> await ReplyAsync(Utils.GetBeep() + Boyfriend.Client.Latency + "мс");
=> await ReplyAsync($"{Utils.GetBeep()}{Boyfriend.Client.Latency}мс");
}

View file

@ -1,23 +0,0 @@
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);
}
}

View file

@ -0,0 +1,29 @@
using Discord;
using Discord.Commands;
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
// ReSharper disable ClassNeverInstantiated.Global
namespace Boyfriend.Commands;
public class UnbanModule : ModuleBase<SocketCommandContext> {
[Command("unban")]
[Summary("Возвращает пользователя из бана")]
[Alias("разбан")]
[RequireBotPermission(GuildPermission.BanMembers)]
[RequireUserPermission(GuildPermission.BanMembers)]
public Task Run(string user, [Remainder] string reason) {
var toBan = Utils.ParseUser(user).Result;
UnbanUser(Context.Guild, Context.User, toBan, reason);
return Task.CompletedTask;
}
public static async void UnbanUser(IGuild guild, IUser author, IUser toUnban, string reason) {
var authorMention = author.Mention;
var notification = $"{authorMention} возвращает из бана {toUnban.Mention} за {Utils.WrapInline(reason)}";
await guild.RemoveBanAsync(toUnban);
await Utils.SilentSendAsync(guild.GetSystemChannelAsync().Result, notification);
await Utils.SilentSendAsync(Utils.GetAdminLogChannel(), notification);
}
}

View file

@ -0,0 +1,29 @@
using Discord;
using Discord.Commands;
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
// ReSharper disable ClassNeverInstantiated.Global
namespace Boyfriend.Commands;
public class UnmuteModule : ModuleBase<SocketCommandContext> {
[Command("unmute")]
[Summary("Возвращает пользователя из мута")]
[Alias("размут")]
[RequireBotPermission(GuildPermission.ManageRoles)]
[RequireUserPermission(GuildPermission.ManageMessages)]
public Task Run(string user, [Remainder] string reason) {
var toUnmute = Utils.ParseMember(Context.Guild, user).Result;
UnmuteMember(Context.Guild, Context.User, toUnmute, reason);
return Task.CompletedTask;
}
public static async void UnmuteMember(IGuild guild, IUser author, IGuildUser toUnmute, string reason) {
var authorMention = author.Mention;
var notification = $"{authorMention} возвращает из мута {toUnmute.Mention} за {Utils.WrapInline(reason)}";
await toUnmute.RemoveRoleAsync(Utils.GetMuteRole(guild));
await Utils.SilentSendAsync(guild.GetSystemChannelAsync().Result, notification);
await Utils.SilentSendAsync(Utils.GetAdminLogChannel(), notification);
}
}