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

every single file changed lulw

This commit is contained in:
l1ttleO 2022-01-30 13:43:15 +05:00
parent f30485dd71
commit 4d838e5af3
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
14 changed files with 825 additions and 511 deletions

View file

@ -28,15 +28,17 @@ public class MuteCommand : Command {
toMute.TimedOutUntil != null && toMute.TimedOutUntil.Value.ToUnixTimeMilliseconds()
> DateTimeOffset.Now.ToUnixTimeMilliseconds())
throw new ApplicationException(Messages.MemberAlreadyMuted);
var rolesRemoved = Boyfriend.GetGuildConfig(context.Guild).RolesRemovedOnMute;
var config = Boyfriend.GetGuildConfig(context.Guild);
var rolesRemoved = config.RolesRemovedOnMute!;
if (rolesRemoved.ContainsKey(toMute.Id)) {
foreach (var roleId in rolesRemoved[toMute.Id]) await toMute.AddRoleAsync(roleId);
rolesRemoved.Remove(toMute.Id);
await config.Save();
await Warn(context.Channel, Messages.RolesReturned);
return;
}
await CommandHandler.CheckPermissions(author, GuildPermission.ManageMessages, GuildPermission.ManageRoles);
await CommandHandler.CheckPermissions(author, GuildPermission.ModerateMembers, GuildPermission.ManageRoles);
await CommandHandler.CheckInteractions(author, toMute);
MuteMember(context.Guild, context.Channel as ITextChannel, context.Guild.GetUser(context.User.Id), toMute,
duration, reason);
@ -48,7 +50,7 @@ public class MuteCommand : Command {
var authorMention = author.Mention;
var role = Utils.GetMuteRole(guild);
var config = Boyfriend.GetGuildConfig(guild);
if (config.RemoveRolesOnMute && role != null) {
if (config.RemoveRolesOnMute.GetValueOrDefault(false) && role != null) {
var rolesRemoved = new List<ulong>();
try {
foreach (var roleId in toMute.RoleIds) {
@ -59,7 +61,7 @@ public class MuteCommand : Command {
}
catch (NullReferenceException) { }
config.RolesRemovedOnMute.Add(toMute.Id, rolesRemoved);
config.RolesRemovedOnMute!.Add(toMute.Id, rolesRemoved);
await config.Save();
}
@ -89,4 +91,4 @@ public class MuteCommand : Command {
public override string GetSummary() {
return "Глушит участника";
}
}
}

View file

@ -7,7 +7,7 @@ namespace Boyfriend.Commands;
public class PingCommand : Command {
public override async Task Run(SocketCommandContext context, string[] args) {
await context.Channel.SendMessageAsync($"{Utils.GetBeep(Boyfriend.GetGuildConfig(context.Guild).Lang)}" +
await context.Channel.SendMessageAsync($"{Utils.GetBeep(Boyfriend.GetGuildConfig(context.Guild).Lang!)}" +
$"{Boyfriend.Client.Latency}{Messages.Milliseconds}");
}
@ -22,4 +22,4 @@ public class PingCommand : Command {
public override string GetSummary() {
return "Измеряет время обработки REST-запроса";
}
}
}

View file

@ -14,71 +14,89 @@ public class SettingsCommand : Command {
var guild = context.Guild;
if (args.Length == 0) {
var nl = Environment.NewLine;
var adminLogChannel = guild.GetTextChannel(config.AdminLogChannel);
var adminLogChannel = guild.GetTextChannel(config.AdminLogChannel.GetValueOrDefault(0));
var admin = adminLogChannel == null ? Messages.ChannelNotSpecified : adminLogChannel.Mention;
var botLogChannel = guild.GetTextChannel(config.BotLogChannel);
var botLogChannel = guild.GetTextChannel(config.BotLogChannel.GetValueOrDefault(0));
var bot = botLogChannel == null ? Messages.ChannelNotSpecified : botLogChannel.Mention;
var muteRole = guild.GetRole(config.MuteRole);
var muteRole = guild.GetRole(config.MuteRole.GetValueOrDefault(0));
var mute = muteRole == null ? Messages.RoleNotSpecified : muteRole.Mention;
var defaultRole = guild.GetRole(config.DefaultRole);
var defaultr = muteRole == null ? Messages.RoleNotSpecified : defaultRole.Mention;
var defaultRole = guild.GetRole(config.DefaultRole.GetValueOrDefault(0));
var defaultr = defaultRole == null ? Messages.RoleNotSpecified : defaultRole.Mention;
var toSend = string.Format(Messages.CurrentSettings, nl) +
string.Format(Messages.CurrentSettingsLang, config.Lang, nl) +
string.Format(Messages.CurrentSettingsPrefix, config.Prefix, nl) +
string.Format(Messages.CurrentSettingsRemoveRoles, YesOrNo(config.RemoveRolesOnMute), nl) +
string.Format(Messages.CurrentSettingsUseSystemChannel, YesOrNo(config.UseSystemChannel), nl) +
string.Format(Messages.CurrentSettingsSendWelcomeMessages, YesOrNo(config.UseSystemChannel),
nl) +
string.Format(Messages.CurrentSettingsRemoveRoles, YesOrNo(
config.RemoveRolesOnMute.GetValueOrDefault(false)), nl) +
string.Format(Messages.CurrentSettingsUseSystemChannel, YesOrNo(
config.UseSystemChannel.GetValueOrDefault(true)), nl) +
string.Format(Messages.CurrentSettingsSendWelcomeMessages, YesOrNo(
config.SendWelcomeMessages.GetValueOrDefault(true)), nl) +
string.Format(Messages.CurrentSettingsReceiveStartupMessages, YesOrNo(
config.ReceiveStartupMessages.GetValueOrDefault(true)), nl) +
string.Format(Messages.CurrentSettingsWelcomeMessage, config.WelcomeMessage, nl) +
string.Format(Messages.CurrentSettingsDefaultRole, defaultr, nl) +
string.Format(Messages.CurrentSettingsMuteRole, mute, nl) +
string.Format(Messages.CurrentSettingsAdminLogChannel, admin, nl) +
string.Format(Messages.CurrentSettingsBotLogChannel, bot);
await Utils.SilentSendAsync(context.Channel as ITextChannel ?? throw new Exception(), toSend);
await Utils.SilentSendAsync(context.Channel as ITextChannel ?? throw new ApplicationException(), toSend);
return;
}
var setting = args[0].ToLower();
var value = args[1].ToLower();
var value = "";
var shouldDefault = false;
if (args.Length >= 2)
value = args[1].ToLower();
else
shouldDefault = true;
var boolValue = ParseBool(args[1]);
var boolValue = ParseBool(value);
var channel = await Utils.ParseChannelNullable(value) as IGuildChannel;
var role = Utils.ParseRoleNullable(guild, value);
switch (setting) {
case "reset":
Boyfriend.ResetGuildConfig(guild);
break;
case "lang" when value is not ("ru" or "en"):
throw new Exception(Messages.LanguageNotSupported);
throw new ApplicationException(Messages.LanguageNotSupported);
case "lang":
config.Lang = value;
Messages.Culture = new CultureInfo(value);
config.Lang = shouldDefault ? "ru" : value;
Messages.Culture = new CultureInfo(shouldDefault ? "ru" : value);
break;
case "prefix":
config.Prefix = value;
config.Prefix = shouldDefault ? "!" : value;
break;
case "removerolesonmute":
config.RemoveRolesOnMute = GetBoolValue(boolValue);
config.RemoveRolesOnMute = !shouldDefault && GetBoolValue(boolValue);
break;
case "usesystemchannel":
config.UseSystemChannel = GetBoolValue(boolValue);
config.UseSystemChannel = shouldDefault || GetBoolValue(boolValue);
break;
case "sendwelcomemessages":
config.SendWelcomeMessages = GetBoolValue(boolValue);
config.SendWelcomeMessages = shouldDefault || GetBoolValue(boolValue);
break;
case "receivestartupmessages":
config.ReceiveStartupMessages = shouldDefault || GetBoolValue(boolValue);
break;
case "welcomemessage":
config.WelcomeMessage = value;
config.WelcomeMessage = shouldDefault ? Messages.DefaultWelcomeMessage : value;
break;
case "defaultrole":
config.DefaultRole = GetRoleId(role);
config.DefaultRole = shouldDefault ? 0 : GetRoleId(role);
break;
case "muterole":
config.MuteRole = GetRoleId(role);
config.MuteRole = shouldDefault ? 0 : GetRoleId(role);
break;
case "adminlogchannel":
config.AdminLogChannel = GetChannelId(channel);
config.AdminLogChannel = shouldDefault ? 0 : GetChannelId(channel);
break;
case "botlogchannel":
config.BotLogChannel = GetChannelId(channel);
config.BotLogChannel = shouldDefault ? 0 : GetChannelId(channel);
break;
default:
await context.Channel.SendMessageAsync(Messages.SettingDoesntExist);
return;
}
await config.Save();
@ -89,22 +107,21 @@ public class SettingsCommand : Command {
private static bool? ParseBool(string toParse) {
try {
return bool.Parse(toParse.ToLower());
}
catch (FormatException) {
} catch (FormatException) {
return null;
}
}
private static bool GetBoolValue(bool? from) {
return from ?? throw new Exception(Messages.InvalidBoolean);
return from ?? throw new ApplicationException(Messages.InvalidBoolean);
}
private static ulong GetRoleId(IRole? role) {
return (role ?? throw new Exception(Messages.InvalidRoleSpecified)).Id;
return (role ?? throw new ApplicationException(Messages.InvalidRoleSpecified)).Id;
}
private static ulong GetChannelId(IGuildChannel? channel) {
return (channel ?? throw new Exception(Messages.InvalidChannelSpecified)).Id;
return (channel ?? throw new ApplicationException(Messages.InvalidChannelSpecified)).Id;
}
private static string YesOrNo(bool isYes) {
@ -122,4 +139,4 @@ public class SettingsCommand : Command {
public override string GetSummary() {
return "Настраивает бота отдельно для этого сервера";
}
}
}

View file

@ -11,7 +11,7 @@ public class UnbanCommand : Command {
public override async Task Run(SocketCommandContext context, string[] args) {
var toUnban = await Utils.ParseUser(args[0]);
if (context.Guild.GetBanAsync(toUnban.Id) == null)
throw new Exception(Messages.UserNotBanned);
throw new ApplicationException(Messages.UserNotBanned);
UnbanUser(context.Guild, context.Channel as ITextChannel, context.Guild.GetUser(context.User.Id), toUnban,
Utils.JoinString(args, 1));
}
@ -40,4 +40,4 @@ public class UnbanCommand : Command {
public override string GetSummary() {
return "Возвращает пользователя из бана";
}
}
}

View file

@ -14,14 +14,21 @@ public class UnmuteCommand : Command {
await CommandHandler.CheckPermissions(author, GuildPermission.ManageMessages, GuildPermission.ManageRoles);
await CommandHandler.CheckInteractions(author, toUnmute);
var role = Utils.GetMuteRole(context.Guild);
if (role != null)
if (role != null) {
if (toUnmute.RoleIds.All(x => x != role.Id)) {
var rolesRemoved = Boyfriend.GetGuildConfig(context.Guild).RolesRemovedOnMute;
var config = Boyfriend.GetGuildConfig(context.Guild);
var rolesRemoved = config.RolesRemovedOnMute;
foreach (var roleId in rolesRemoved[toUnmute.Id]) await toUnmute.AddRoleAsync(roleId);
foreach (var roleId in rolesRemoved![toUnmute.Id]) await toUnmute.AddRoleAsync(roleId);
rolesRemoved.Remove(toUnmute.Id);
await config.Save();
throw new ApplicationException(Messages.RolesReturned);
}
}
if (role != null && toUnmute.RoleIds.All(x => x != role.Id) ||
toUnmute.TimedOutUntil == null || toUnmute.TimedOutUntil.Value.ToUnixTimeMilliseconds()
< DateTimeOffset.Now.ToUnixTimeMilliseconds())
throw new ApplicationException(Messages.MemberNotMuted);
UnmuteMember(context.Guild, context.Channel as ITextChannel, context.Guild.GetUser(context.User.Id),
toUnmute, Utils.JoinString(args, 1));
@ -33,12 +40,19 @@ public class UnmuteCommand : Command {
var authorMention = author.Mention;
var notification = string.Format(Messages.MemberUnmuted, authorMention, toUnmute.Mention,
Utils.WrapInline(reason));
await toUnmute.RemoveRoleAsync(Utils.GetMuteRole(guild));
var config = Boyfriend.GetGuildConfig(guild);
var role = Utils.GetMuteRole(guild);
if (config.RolesRemovedOnMute.ContainsKey(toUnmute.Id)) {
foreach (var roleId in config.RolesRemovedOnMute[toUnmute.Id]) await toUnmute.AddRoleAsync(roleId);
config.RolesRemovedOnMute.Remove(toUnmute.Id);
if (role != null) {
await toUnmute.RemoveRoleAsync(role);
var config = Boyfriend.GetGuildConfig(guild);
if (config.RolesRemovedOnMute!.ContainsKey(toUnmute.Id)) {
foreach (var roleId in config.RolesRemovedOnMute[toUnmute.Id]) await toUnmute.AddRoleAsync(roleId);
config.RolesRemovedOnMute.Remove(toUnmute.Id);
await config.Save();
}
} else {
await toUnmute.RemoveTimeOutAsync();
}
await Utils.SilentSendAsync(channel, string.Format(Messages.UnmuteResponse, toUnmute.Mention,
@ -58,4 +72,4 @@ public class UnmuteCommand : Command {
public override string GetSummary() {
return "Снимает мут с участника";
}
}
}