mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-10 16:03:15 +03:00
Continue adapting code to new guild data storage
This commit is contained in:
parent
163e3ac46b
commit
fe2cfb3b3c
10 changed files with 145 additions and 94 deletions
|
@ -28,12 +28,14 @@ public sealed class BanCommand : ICommand {
|
|||
var guildBanMessage = $"({author}) {reason}";
|
||||
await guild.AddBanAsync(toBan, 0, guildBanMessage);
|
||||
|
||||
var memberData = GuildData.FromSocketGuild(guild).MemberData[toBan.Id];
|
||||
memberData.BannedUntil
|
||||
= duration.TotalSeconds < 1 ? -1 : DateTimeOffset.Now.Add(duration).ToUnixTimeSeconds();
|
||||
memberData.Roles.Clear();
|
||||
|
||||
var feedback = string.Format(Messages.FeedbackUserBanned, toBan.Mention,
|
||||
Utils.GetHumanizedTimeOffset(duration), Utils.Wrap(reason));
|
||||
cmd.Reply(feedback, ReplyEmojis.Banned);
|
||||
cmd.Audit(feedback);
|
||||
|
||||
GuildData.FromSocketGuild(guild).MemberData[toBan.Id].BannedUntil
|
||||
= DateTimeOffset.Now.Add(duration).ToUnixTimeSeconds();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using Boyfriend.Data;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
|
||||
|
@ -22,6 +23,8 @@ public sealed class KickCommand : ICommand {
|
|||
string.Format(Messages.YouWereKicked, cmd.Context.User.Mention, cmd.Context.Guild.Name,
|
||||
Utils.Wrap(reason)));
|
||||
|
||||
GuildData.FromSocketGuild(cmd.Context.Guild).MemberData[toKick.Id].Roles.Clear();
|
||||
|
||||
await toKick.KickAsync(guildKickMessage);
|
||||
var format = string.Format(Messages.FeedbackMemberKicked, toKick.Mention, Utils.Wrap(reason));
|
||||
cmd.Reply(format, ReplyEmojis.Kicked);
|
||||
|
|
|
@ -36,7 +36,8 @@ public sealed class MuteCommand : ICommand {
|
|||
var hasDuration = duration.TotalSeconds > 0;
|
||||
|
||||
if (role is not null) {
|
||||
if (data.Preferences["RemoveRolesOnMute"] is "true") await toMute.RemoveRolesAsync(toMute.Roles);
|
||||
if (data.Preferences["RemoveRolesOnMute"] is "true")
|
||||
await toMute.RemoveRolesAsync(toMute.Roles, requestOptions);
|
||||
|
||||
await toMute.AddRoleAsync(role, requestOptions);
|
||||
|
||||
|
|
19
Boyfriend/Commands/RemindCommand.cs
Normal file
19
Boyfriend/Commands/RemindCommand.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using Boyfriend.Data;
|
||||
|
||||
namespace Boyfriend.Commands;
|
||||
|
||||
public sealed class RemindCommand : ICommand {
|
||||
public string[] Aliases { get; } = { "remind", "reminder", "remindme", "напомни", "напомнить", "напоминание" };
|
||||
|
||||
public Task RunAsync(CommandProcessor cmd, string[] args, string[] cleanArgs) {
|
||||
var remindIn = CommandProcessor.GetTimeSpan(args, 0);
|
||||
var reminderText = cmd.GetRemaining(args, 1, "ReminderText");
|
||||
if (reminderText is not null)
|
||||
GuildData.FromSocketGuild(cmd.Context.Guild).MemberData[cmd.Context.User.Id].Reminders.Add(new Reminder {
|
||||
RemindAt = DateTimeOffset.Now.Add(remindIn).ToUnixTimeSeconds(),
|
||||
ReminderText = reminderText
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ public sealed class SettingsCommand : ICommand {
|
|||
if (args.Length is 0) {
|
||||
var currentSettings = Boyfriend.StringBuilder.AppendLine(Messages.CurrentSettings);
|
||||
|
||||
foreach (var setting in GuildData.DefaultConfiguration) {
|
||||
foreach (var setting in GuildData.DefaultPreferences) {
|
||||
var format = "{0}";
|
||||
var currentValue = config[setting.Key] is "default"
|
||||
? Messages.DefaultWelcomeMessage
|
||||
|
@ -47,7 +47,7 @@ public sealed class SettingsCommand : ICommand {
|
|||
var exists = false;
|
||||
// ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator
|
||||
// Too many allocations
|
||||
foreach (var setting in GuildData.DefaultConfiguration.Keys) {
|
||||
foreach (var setting in GuildData.DefaultPreferences.Keys) {
|
||||
if (selectedSetting != setting.ToLower()) continue;
|
||||
selectedSetting = setting;
|
||||
exists = true;
|
||||
|
@ -74,7 +74,7 @@ public sealed class SettingsCommand : ICommand {
|
|||
}
|
||||
} else { value = "reset"; }
|
||||
|
||||
if (IsBool(GuildData.DefaultConfiguration[selectedSetting]) && !IsBool(value)) {
|
||||
if (IsBool(GuildData.DefaultPreferences[selectedSetting]) && !IsBool(value)) {
|
||||
value = value switch {
|
||||
"y" or "yes" or "д" or "да" => "true",
|
||||
"n" or "no" or "н" or "нет" => "false",
|
||||
|
@ -99,14 +99,14 @@ public sealed class SettingsCommand : ICommand {
|
|||
|
||||
var formattedValue = selectedSetting switch {
|
||||
"WelcomeMessage" => Utils.Wrap(Messages.DefaultWelcomeMessage),
|
||||
"EventStartedReceivers" => Utils.Wrap(GuildData.DefaultConfiguration[selectedSetting])!,
|
||||
"EventStartedReceivers" => Utils.Wrap(GuildData.DefaultPreferences[selectedSetting])!,
|
||||
_ => value is "reset" or "default" ? Messages.SettingNotDefined
|
||||
: IsBool(value) ? YesOrNo(value is "true")
|
||||
: string.Format(formatting, value)
|
||||
};
|
||||
|
||||
if (value is "reset" or "default") {
|
||||
config[selectedSetting] = GuildData.DefaultConfiguration[selectedSetting];
|
||||
config[selectedSetting] = GuildData.DefaultPreferences[selectedSetting];
|
||||
} else {
|
||||
if (value == config[selectedSetting]) {
|
||||
cmd.Reply(string.Format(Messages.SettingsNothingChanged, localizedSelectedSetting, formattedValue),
|
||||
|
@ -139,7 +139,7 @@ public sealed class SettingsCommand : ICommand {
|
|||
}
|
||||
|
||||
if (selectedSetting is "Lang") {
|
||||
Utils.SetCurrentLanguage(guild.Id);
|
||||
Utils.SetCurrentLanguage(guild);
|
||||
localizedSelectedSetting = Utils.GetMessage($"Settings{selectedSetting}");
|
||||
}
|
||||
|
||||
|
|
|
@ -20,10 +20,12 @@ public sealed class UnmuteCommand : ICommand {
|
|||
public static async Task UnmuteMemberAsync(CommandProcessor cmd, SocketGuildUser toUnmute,
|
||||
string reason) {
|
||||
var requestOptions = Utils.GetRequestOptions($"({cmd.Context.User}) {reason}");
|
||||
var role = GuildData.FromSocketGuild(cmd.Context.Guild).MuteRole;
|
||||
var data = GuildData.FromSocketGuild(cmd.Context.Guild);
|
||||
var role = data.MuteRole;
|
||||
|
||||
if (role is not null && toUnmute.Roles.Contains(role)) {
|
||||
// TODO: Return roles
|
||||
await toUnmute.AddRolesAsync(data.MemberData[toUnmute.Id].Roles, requestOptions);
|
||||
await toUnmute.RemoveRoleAsync(role, requestOptions);
|
||||
} else {
|
||||
if (toUnmute.TimedOutUntil is null || toUnmute.TimedOutUntil.Value.ToUnixTimeSeconds() <
|
||||
DateTimeOffset.Now.ToUnixTimeSeconds()) {
|
||||
|
@ -31,7 +33,7 @@ public sealed class UnmuteCommand : ICommand {
|
|||
return;
|
||||
}
|
||||
|
||||
await toUnmute.RemoveTimeOutAsync();
|
||||
await toUnmute.RemoveTimeOutAsync(requestOptions);
|
||||
}
|
||||
|
||||
var feedback = string.Format(Messages.FeedbackMemberUnmuted, toUnmute.Mention, Utils.Wrap(reason));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue