mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-04 21:16:29 +03:00
more stuff. yeah
This commit is contained in:
parent
382add19a3
commit
270fba5c3c
13 changed files with 301 additions and 116 deletions
|
@ -12,18 +12,26 @@ public class BanModule : ModuleBase<SocketCommandContext> {
|
|||
[Command("ban")]
|
||||
[Summary("Банит пользователя")]
|
||||
[Alias("бан")]
|
||||
[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 Task Run(string user, string durationString, [Remainder]string reason) {
|
||||
TimeSpan duration;
|
||||
try {
|
||||
duration = TimeSpan.Parse(durationString);
|
||||
} catch (Exception e) when (e is ArgumentNullException or FormatException or OverflowException) {
|
||||
duration = TimeSpan.FromMilliseconds(-1);
|
||||
reason = durationString + reason;
|
||||
}
|
||||
var author = Context.Guild.GetUser(Context.User.Id);
|
||||
var toBan = await Utils.ParseUser(user);
|
||||
await CommandHandler.CheckPermissions(author, GuildPermission.BanMembers);
|
||||
var memberToBan = Context.Guild.GetUser(toBan.Id);
|
||||
if (memberToBan != null)
|
||||
await CommandHandler.CheckInteractions(author, memberToBan);
|
||||
BanUser(Context.Guild, Context.Guild.GetUser(Context.User.Id), toBan, duration, reason);
|
||||
}
|
||||
|
||||
public static async void BanUser(IGuild guild, IUser author, IUser toBan, TimeSpan duration, string reason) {
|
||||
public static async void BanUser(IGuild guild, IGuildUser author, IUser toBan, TimeSpan duration, string reason) {
|
||||
var authorMention = author.Mention;
|
||||
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)}";
|
||||
|
|
|
@ -12,15 +12,14 @@ 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;
|
||||
await CommandHandler.CheckPermissions(Context.Guild.GetUser(Context.User.Id), GuildPermission.ManageMessages);
|
||||
switch (toDelete) {
|
||||
case < 1:
|
||||
throw new ArgumentException("toDelete is less than 1.");
|
||||
throw new Exception( "Указано отрицательное количество сообщений!");
|
||||
case > 200:
|
||||
throw new ArgumentException("toDelete is more than 200.");
|
||||
throw new Exception("Указано слишком много сообщений!");
|
||||
default: {
|
||||
var messages = await channel.GetMessagesAsync(toDelete + 1).FlattenAsync();
|
||||
await channel.DeleteMessagesAsync(messages);
|
||||
|
|
25
Boyfriend/Commands/HelpModule.cs
Normal file
25
Boyfriend/Commands/HelpModule.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using Discord.Commands;
|
||||
// ReSharper disable UnusedType.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
namespace Boyfriend.Commands;
|
||||
|
||||
public class HelpModule : ModuleBase<SocketCommandContext> {
|
||||
|
||||
[Command("help")]
|
||||
[Summary("Показывает эту справку")]
|
||||
[Alias("помощь", "справка")]
|
||||
public Task Run() {
|
||||
var nl = Environment.NewLine;
|
||||
var toSend = $"Справка по командам:{nl}";
|
||||
var prefix = Boyfriend.GetGuildConfig(Context.Guild).Prefix;
|
||||
foreach (var command in EventHandler.Commands.Commands) {
|
||||
var aliases = command.Aliases.Aggregate("", (current, alias) =>
|
||||
current + (current == "" ? "" : $", {prefix}") + alias);
|
||||
toSend += $"`{prefix}{aliases}`: {command.Summary}{nl}";
|
||||
}
|
||||
|
||||
Context.Channel.SendMessageAsync(toSend);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
|
@ -12,15 +12,15 @@ public class KickModule : ModuleBase<SocketCommandContext> {
|
|||
[Command("kick")]
|
||||
[Summary("Выгоняет пользователя")]
|
||||
[Alias("кик")]
|
||||
[RequireBotPermission(GuildPermission.KickMembers)]
|
||||
[RequireUserPermission(GuildPermission.KickMembers)]
|
||||
public Task Run(string user, [Remainder]string reason) {
|
||||
public async Task Run(string user, [Remainder]string reason) {
|
||||
var author = Context.Guild.GetUser(Context.User.Id);
|
||||
var toKick = Utils.ParseMember(Context.Guild, user).Result;
|
||||
KickMember(Context.Guild, Context.User, toKick, reason);
|
||||
return Task.CompletedTask;
|
||||
await CommandHandler.CheckPermissions(author, GuildPermission.KickMembers);
|
||||
await CommandHandler.CheckInteractions(author, toKick);
|
||||
KickMember(Context.Guild, Context.Guild.GetUser(Context.User.Id), toKick, reason);
|
||||
}
|
||||
|
||||
private static async void KickMember(IGuild guild, IUser author, IGuildUser toKick, string reason) {
|
||||
private static async void KickMember(IGuild guild, IGuildUser author, IGuildUser toKick, string reason) {
|
||||
var authorMention = author.Mention;
|
||||
await Utils.SendDirectMessage(toKick, $"Тебя кикнул {authorMention} на сервере {guild.Name} за " +
|
||||
$"{Utils.WrapInline(reason)}");
|
||||
|
|
|
@ -12,18 +12,33 @@ 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;
|
||||
public async Task Run(string user, string durationString, [Remainder]string reason) {
|
||||
TimeSpan duration;
|
||||
try {
|
||||
duration = TimeSpan.Parse(durationString);
|
||||
} catch (Exception e) when (e is ArgumentNullException or FormatException or OverflowException) {
|
||||
duration = TimeSpan.FromMilliseconds(-1);
|
||||
reason = durationString + reason;
|
||||
}
|
||||
var author = Context.Guild.GetUser(Context.User.Id);
|
||||
var toMute = await Utils.ParseMember(Context.Guild, user);
|
||||
await CommandHandler.CheckPermissions(author, GuildPermission.ManageMessages, GuildPermission.ManageRoles);
|
||||
await CommandHandler.CheckInteractions(author, toMute);
|
||||
MuteMember(Context.Guild, Context.Guild.GetUser(Context.User.Id), toMute, duration, reason);
|
||||
}
|
||||
|
||||
private static async void MuteMember(IGuild guild, IMentionable author, IGuildUser toMute, TimeSpan duration,
|
||||
private static async void MuteMember(IGuild guild, IGuildUser author, IGuildUser toMute, TimeSpan duration,
|
||||
string reason) {
|
||||
await CommandHandler.CheckPermissions(author, GuildPermission.ManageMessages, GuildPermission.ManageRoles);
|
||||
var authorMention = author.Mention;
|
||||
var role = Utils.GetMuteRole(guild);
|
||||
if (Boyfriend.GetGuildConfig(guild).RemoveRolesOnMute) {
|
||||
foreach (var roleId in toMute.RoleIds) {
|
||||
await toMute.RemoveRoleAsync(roleId);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
await toMute.AddRoleAsync(role);
|
||||
var notification = $"{authorMention} глушит {toMute.Mention} за {Utils.WrapInline(reason)}";
|
||||
await Utils.SilentSendAsync(guild.GetSystemChannelAsync().Result, notification);
|
||||
|
|
46
Boyfriend/Commands/SettingsModule.cs
Normal file
46
Boyfriend/Commands/SettingsModule.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using Discord.Commands;
|
||||
// ReSharper disable UnusedType.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
namespace Boyfriend.Commands;
|
||||
|
||||
public class SettingsModule : ModuleBase<SocketCommandContext> {
|
||||
|
||||
[Command("settings")]
|
||||
[Summary("Настраивает бота")]
|
||||
[Alias("config", "настройки", "конфиг")]
|
||||
public async Task Run([Remainder] string s = "") {
|
||||
var config = Boyfriend.GetGuildConfig(Context.Guild);
|
||||
var sArray = s.Split(" ");
|
||||
if (s == "") {
|
||||
var nl = Environment.NewLine;
|
||||
await Context.Channel.SendMessageAsync($"Текущие настройки:{nl}Язык: `{config.Lang}`" +
|
||||
$"{nl}Префикс: `{config.Prefix}`" +
|
||||
$"{nl}Удалять роли при муте: " +
|
||||
$"{(config.RemoveRolesOnMute ? "Да" : "Нет")}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sArray[0].ToLower() == "lang") {
|
||||
if (sArray[1].ToLower() != "ru") throw new Exception("Язык не поддерживается!");
|
||||
config.Lang = sArray[1].ToLower();
|
||||
}
|
||||
|
||||
|
||||
if (sArray[0].ToLower() == "prefix")
|
||||
config.Prefix = sArray[1];
|
||||
|
||||
if (sArray[0].ToLower() == "removerolesonmute") {
|
||||
try {
|
||||
config.RemoveRolesOnMute = bool.Parse(sArray[1].ToLower());
|
||||
} catch (FormatException) {
|
||||
await Context.Channel.SendMessageAsync("Неверный параметр! Требуется `true` или `false`");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
config.Save();
|
||||
|
||||
await Context.Channel.SendMessageAsync("Настройки успешно обновлены!");
|
||||
}
|
||||
}
|
|
@ -11,15 +11,16 @@ 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);
|
||||
var toUnban = Utils.ParseUser(user).Result;
|
||||
if (Context.Guild.GetBanAsync(toUnban.Id) == null)
|
||||
throw new Exception("Пользователь не забанен!");
|
||||
UnbanUser(Context.Guild, Context.Guild.GetUser(Context.User.Id), toUnban, reason);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public static async void UnbanUser(IGuild guild, IUser author, IUser toUnban, string reason) {
|
||||
public static async void UnbanUser(IGuild guild, IGuildUser author, IUser toUnban, string reason) {
|
||||
await CommandHandler.CheckPermissions(author, GuildPermission.BanMembers);
|
||||
var authorMention = author.Mention;
|
||||
var notification = $"{authorMention} возвращает из бана {toUnban.Mention} за {Utils.WrapInline(reason)}";
|
||||
await guild.RemoveBanAsync(toUnban);
|
||||
|
|
|
@ -11,15 +11,18 @@ public class UnmuteModule : ModuleBase<SocketCommandContext> {
|
|||
[Command("unmute")]
|
||||
[Summary("Возвращает пользователя из мута")]
|
||||
[Alias("размут")]
|
||||
[RequireBotPermission(GuildPermission.ManageRoles)]
|
||||
[RequireUserPermission(GuildPermission.ManageMessages)]
|
||||
public Task Run(string user, [Remainder] string reason) {
|
||||
public async 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;
|
||||
var author = Context.Guild.GetUser(Context.User.Id);
|
||||
await CommandHandler.CheckPermissions(author, GuildPermission.ManageMessages, GuildPermission.ManageRoles);
|
||||
await CommandHandler.CheckInteractions(author, toUnmute);
|
||||
if (toUnmute.RoleIds.All(x => x != Utils.GetMuteRole(Context.Guild).Id))
|
||||
throw new Exception("Пользователь не в муте!");
|
||||
UnmuteMember(Context.Guild, Context.Guild.GetUser(Context.User.Id), toUnmute, reason);
|
||||
}
|
||||
|
||||
public static async void UnmuteMember(IGuild guild, IUser author, IGuildUser toUnmute, string reason) {
|
||||
public static async void UnmuteMember(IGuild guild, IGuildUser author, IGuildUser toUnmute, string reason) {
|
||||
await CommandHandler.CheckPermissions(author, GuildPermission.ManageMessages, GuildPermission.ManageRoles);
|
||||
var authorMention = author.Mention;
|
||||
var notification = $"{authorMention} возвращает из мута {toUnmute.Mention} за {Utils.WrapInline(reason)}";
|
||||
await toUnmute.RemoveRoleAsync(Utils.GetMuteRole(guild));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue