mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-01-31 09:09:00 +03:00
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 DateTimeOffset _nextSongAt = DateTimeOffset.MinValue;
|
||||||
private static uint _nextSongIndex;
|
private static uint _nextSongIndex;
|
||||||
|
|
||||||
private static readonly Tuple<Game, TimeSpan>[] ActivityList = {
|
private static readonly (Game Song, TimeSpan Duration)[] ActivityList = {
|
||||||
Tuple.Create(
|
(new Game("Masayoshi Minoshima (ft. nomico) - Bad Apple!!", ActivityType.Listening), new TimeSpan(0, 3, 40)),
|
||||||
new Game("Masayoshi Minoshima (ft. nomico) - Bad Apple!!", ActivityType.Listening),
|
(new Game("Xi - Blue Zenith", ActivityType.Listening), new TimeSpan(0, 4, 16)),
|
||||||
new TimeSpan(0, 3, 40)),
|
(new Game("UNDEAD CORPORATION - Everything will freeze", ActivityType.Listening), new TimeSpan(0, 3, 18)),
|
||||||
Tuple.Create(new Game("Xi - Blue Zenith", ActivityType.Listening), new TimeSpan(0, 4, 16)),
|
(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)),
|
||||||
new Game("UNDEAD CORPORATION - Everything will freeze", ActivityType.Listening), new TimeSpan(0, 3, 18)),
|
(new Game("beatMARIO - Night of Knights", ActivityType.Listening), new TimeSpan(0, 4, 10))
|
||||||
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))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public static readonly DiscordSocketClient Client = new(Config);
|
public static readonly DiscordSocketClient Client = new(Config);
|
||||||
|
@ -73,8 +70,8 @@ public static class Boyfriend {
|
||||||
|
|
||||||
if (now >= _nextSongAt) {
|
if (now >= _nextSongAt) {
|
||||||
var nextSong = ActivityList[_nextSongIndex];
|
var nextSong = ActivityList[_nextSongIndex];
|
||||||
await Client.SetActivityAsync(nextSong.Item1);
|
await Client.SetActivityAsync(nextSong.Song);
|
||||||
_nextSongAt = now.Add(nextSong.Item2);
|
_nextSongAt = now.Add(nextSong.Duration);
|
||||||
_nextSongIndex++;
|
_nextSongIndex++;
|
||||||
if (_nextSongIndex >= ActivityList.Length) _nextSongIndex = 0;
|
if (_nextSongIndex >= ActivityList.Length) _nextSongIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,7 @@ public sealed class CommandProcessor {
|
||||||
return null;
|
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) {
|
if (index >= args.Length) {
|
||||||
Utils.SafeAppendToBuilder(
|
Utils.SafeAppendToBuilder(
|
||||||
_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingUser}",
|
_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingUser}",
|
||||||
|
@ -144,7 +144,7 @@ public sealed class CommandProcessor {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Tuple.Create(mention, Boyfriend.Client.GetUser(mention))!;
|
return (mention, Boyfriend.Client.GetUser(mention));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasPermission(GuildPermission permission) {
|
public bool HasPermission(GuildPermission permission) {
|
||||||
|
|
|
@ -11,33 +11,36 @@ public sealed class BanCommand : ICommand {
|
||||||
var toBan = cmd.GetUser(args, cleanArgs, 0);
|
var toBan = cmd.GetUser(args, cleanArgs, 0);
|
||||||
if (toBan is null || !cmd.HasPermission(GuildPermission.BanMembers)) return;
|
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;
|
if (memberToBan is not null && !cmd.CanInteractWith(memberToBan, "Ban")) return;
|
||||||
|
|
||||||
var duration = CommandProcessor.GetTimeSpan(args, 1);
|
var duration = CommandProcessor.GetTimeSpan(args, 1);
|
||||||
var reason = cmd.GetRemaining(args, duration.TotalSeconds < 1 ? 1 : 2, "BanReason");
|
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(
|
||||||
string reason) {
|
CommandProcessor cmd, (ulong Id, SocketUser? User) toBan, TimeSpan duration,
|
||||||
|
string reason) {
|
||||||
var author = cmd.Context.User;
|
var author = cmd.Context.User;
|
||||||
var guild = cmd.Context.Guild;
|
var guild = cmd.Context.Guild;
|
||||||
if (toBan.Item2 is not null)
|
if (toBan.User is not null)
|
||||||
await Utils.SendDirectMessage(toBan.Item2,
|
await Utils.SendDirectMessage(
|
||||||
|
toBan.User,
|
||||||
string.Format(Messages.YouWereBanned, author.Mention, guild.Name, Utils.Wrap(reason)));
|
string.Format(Messages.YouWereBanned, author.Mention, guild.Name, Utils.Wrap(reason)));
|
||||||
|
|
||||||
var guildBanMessage = $"({author}) {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
|
memberData.BannedUntil
|
||||||
= duration.TotalSeconds < 1 ? DateTimeOffset.MaxValue : DateTimeOffset.Now.Add(duration);
|
= duration.TotalSeconds < 1 ? DateTimeOffset.MaxValue : DateTimeOffset.Now.Add(duration);
|
||||||
memberData.Roles.Clear();
|
memberData.Roles.Clear();
|
||||||
|
|
||||||
cmd.ConfigWriteScheduled = true;
|
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));
|
Utils.GetHumanizedTimeSpan(duration), Utils.Wrap(reason));
|
||||||
cmd.Reply(feedback, ReplyEmojis.Banned);
|
cmd.Reply(feedback, ReplyEmojis.Banned);
|
||||||
cmd.Audit(feedback);
|
cmd.Audit(feedback);
|
||||||
|
|
Loading…
Reference in a new issue