forked from TeamInklings/Octobot
Use modern Tuple syntax
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
30a4a94f1b
commit
f6f5543972
3 changed files with 23 additions and 23 deletions
21
Boyfriend.cs
21
Boyfriend.cs
|
@ -25,16 +25,13 @@ public static class Boyfriend {
|
|||
private static DateTimeOffset _nextSongAt = DateTimeOffset.MinValue;
|
||||
private static uint _nextSongIndex;
|
||||
|
||||
private static readonly Tuple<Game, TimeSpan>[] ActivityList = {
|
||||
Tuple.Create(
|
||||
new Game("Masayoshi Minoshima (ft. nomico) - Bad Apple!!", ActivityType.Listening),
|
||||
new TimeSpan(0, 3, 40)),
|
||||
Tuple.Create(new Game("Xi - Blue Zenith", ActivityType.Listening), new TimeSpan(0, 4, 16)),
|
||||
Tuple.Create(
|
||||
new Game("UNDEAD CORPORATION - Everything will freeze", ActivityType.Listening), new TimeSpan(0, 3, 18)),
|
||||
Tuple.Create(new Game("Splatoon 3 - Candy-Coated Rocks", ActivityType.Listening), new TimeSpan(0, 2, 39)),
|
||||
Tuple.Create(new Game("RetroSpecter - Overtime", ActivityType.Listening), new TimeSpan(0, 4, 33)),
|
||||
Tuple.Create(new Game("beatMARIO - Night of Knights", ActivityType.Listening), new TimeSpan(0, 4, 10))
|
||||
private static readonly (Game Song, TimeSpan Duration)[] ActivityList = {
|
||||
(new Game("Masayoshi Minoshima (ft. nomico) - Bad Apple!!", ActivityType.Listening), new TimeSpan(0, 3, 40)),
|
||||
(new Game("Xi - Blue Zenith", ActivityType.Listening), new TimeSpan(0, 4, 16)),
|
||||
(new Game("UNDEAD CORPORATION - Everything will freeze", ActivityType.Listening), new TimeSpan(0, 3, 18)),
|
||||
(new Game("Splatoon 3 - Candy-Coated Rocks", ActivityType.Listening), new TimeSpan(0, 2, 39)),
|
||||
(new Game("RetroSpecter - Overtime", ActivityType.Listening), new TimeSpan(0, 4, 33)),
|
||||
(new Game("beatMARIO - Night of Knights", ActivityType.Listening), new TimeSpan(0, 4, 10))
|
||||
};
|
||||
|
||||
public static readonly DiscordSocketClient Client = new(Config);
|
||||
|
@ -73,8 +70,8 @@ public static class Boyfriend {
|
|||
|
||||
if (now >= _nextSongAt) {
|
||||
var nextSong = ActivityList[_nextSongIndex];
|
||||
await Client.SetActivityAsync(nextSong.Item1);
|
||||
_nextSongAt = now.Add(nextSong.Item2);
|
||||
await Client.SetActivityAsync(nextSong.Song);
|
||||
_nextSongAt = now.Add(nextSong.Duration);
|
||||
_nextSongIndex++;
|
||||
if (_nextSongIndex >= ActivityList.Length) _nextSongIndex = 0;
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ public sealed class CommandProcessor {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Tuple<ulong, SocketUser?>? GetUser(string[] args, string[] cleanArgs, int index) {
|
||||
public (ulong Id, SocketUser? User)? GetUser(string[] args, string[] cleanArgs, int index) {
|
||||
if (index >= args.Length) {
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingUser}",
|
||||
|
@ -144,7 +144,7 @@ public sealed class CommandProcessor {
|
|||
return null;
|
||||
}
|
||||
|
||||
return Tuple.Create(mention, Boyfriend.Client.GetUser(mention))!;
|
||||
return (mention, Boyfriend.Client.GetUser(mention));
|
||||
}
|
||||
|
||||
public bool HasPermission(GuildPermission permission) {
|
||||
|
|
|
@ -11,33 +11,36 @@ public sealed class BanCommand : ICommand {
|
|||
var toBan = cmd.GetUser(args, cleanArgs, 0);
|
||||
if (toBan is null || !cmd.HasPermission(GuildPermission.BanMembers)) return;
|
||||
|
||||
var memberToBan = cmd.GetMember(toBan.Item1);
|
||||
var memberToBan = cmd.GetMember(toBan.Value.Id);
|
||||
if (memberToBan is not null && !cmd.CanInteractWith(memberToBan, "Ban")) return;
|
||||
|
||||
var duration = CommandProcessor.GetTimeSpan(args, 1);
|
||||
var reason = cmd.GetRemaining(args, duration.TotalSeconds < 1 ? 1 : 2, "BanReason");
|
||||
if (reason is not null) await BanUserAsync(cmd, toBan, duration, reason);
|
||||
if (reason is not null) await BanUserAsync(cmd, toBan.Value, duration, reason);
|
||||
}
|
||||
|
||||
private static async Task BanUserAsync(CommandProcessor cmd, Tuple<ulong, SocketUser?> toBan, TimeSpan duration,
|
||||
private static async Task BanUserAsync(
|
||||
CommandProcessor cmd, (ulong Id, SocketUser? User) toBan, TimeSpan duration,
|
||||
string reason) {
|
||||
var author = cmd.Context.User;
|
||||
var guild = cmd.Context.Guild;
|
||||
if (toBan.Item2 is not null)
|
||||
await Utils.SendDirectMessage(toBan.Item2,
|
||||
if (toBan.User is not null)
|
||||
await Utils.SendDirectMessage(
|
||||
toBan.User,
|
||||
string.Format(Messages.YouWereBanned, author.Mention, guild.Name, Utils.Wrap(reason)));
|
||||
|
||||
var guildBanMessage = $"({author}) {reason}";
|
||||
await guild.AddBanAsync(toBan.Item1, 0, guildBanMessage);
|
||||
await guild.AddBanAsync(toBan.Id, 0, guildBanMessage);
|
||||
|
||||
var memberData = GuildData.Get(guild).MemberData[toBan.Item1];
|
||||
var memberData = GuildData.Get(guild).MemberData[toBan.Id];
|
||||
memberData.BannedUntil
|
||||
= duration.TotalSeconds < 1 ? DateTimeOffset.MaxValue : DateTimeOffset.Now.Add(duration);
|
||||
memberData.Roles.Clear();
|
||||
|
||||
cmd.ConfigWriteScheduled = true;
|
||||
|
||||
var feedback = string.Format(Messages.FeedbackUserBanned, $"<@{toBan.Item1.ToString()}>",
|
||||
var feedback = string.Format(
|
||||
Messages.FeedbackUserBanned, $"<@{toBan.Id.ToString()}>",
|
||||
Utils.GetHumanizedTimeSpan(duration), Utils.Wrap(reason));
|
||||
cmd.Reply(feedback, ReplyEmojis.Banned);
|
||||
cmd.Audit(feedback);
|
||||
|
|
Reference in a new issue