forked from TeamInklings/Octobot
Reduce indenting, fix critical bug with private feedback being public and vice versa
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
6f5a969704
commit
0bdf2cd33e
3 changed files with 166 additions and 116 deletions
35
Boyfriend.cs
35
Boyfriend.cs
|
@ -14,8 +14,8 @@ public static class Boyfriend {
|
||||||
private static readonly DiscordSocketConfig Config = new() {
|
private static readonly DiscordSocketConfig Config = new() {
|
||||||
MessageCacheSize = 250,
|
MessageCacheSize = 250,
|
||||||
GatewayIntents
|
GatewayIntents
|
||||||
= (GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent | GatewayIntents.GuildMembers) &
|
= (GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent | GatewayIntents.GuildMembers)
|
||||||
~GatewayIntents.GuildInvites,
|
& ~GatewayIntents.GuildInvites,
|
||||||
AlwaysDownloadUsers = true,
|
AlwaysDownloadUsers = true,
|
||||||
AlwaysResolveStickers = false,
|
AlwaysResolveStickers = false,
|
||||||
AlwaysDownloadDefaultStickers = false,
|
AlwaysDownloadDefaultStickers = false,
|
||||||
|
@ -26,7 +26,8 @@ public static class Boyfriend {
|
||||||
private static uint _nextSongIndex;
|
private static uint _nextSongIndex;
|
||||||
|
|
||||||
private static readonly Tuple<Game, TimeSpan>[] ActivityList = {
|
private static readonly Tuple<Game, TimeSpan>[] ActivityList = {
|
||||||
Tuple.Create(new Game("Masayoshi Minoshima (ft. nomico) - Bad Apple!!", ActivityType.Listening),
|
Tuple.Create(
|
||||||
|
new Game("Masayoshi Minoshima (ft. nomico) - Bad Apple!!", ActivityType.Listening),
|
||||||
new TimeSpan(0, 3, 40)),
|
new TimeSpan(0, 3, 40)),
|
||||||
Tuple.Create(new Game("Xi - Blue Zenith", ActivityType.Listening), new TimeSpan(0, 4, 16)),
|
Tuple.Create(new Game("Xi - Blue Zenith", ActivityType.Listening), new TimeSpan(0, 4, 16)),
|
||||||
Tuple.Create(new Game("Kurokotei - Scattered Faith", ActivityType.Listening), new TimeSpan(0, 8, 21)),
|
Tuple.Create(new Game("Kurokotei - Scattered Faith", ActivityType.Listening), new TimeSpan(0, 8, 21)),
|
||||||
|
@ -75,7 +76,9 @@ public static class Boyfriend {
|
||||||
|
|
||||||
try { Task.WaitAll(GuildTickTasks.ToArray()); } catch (AggregateException ex) {
|
try { Task.WaitAll(GuildTickTasks.ToArray()); } catch (AggregateException ex) {
|
||||||
foreach (var exc in ex.InnerExceptions)
|
foreach (var exc in ex.InnerExceptions)
|
||||||
await Log(new LogMessage(LogSeverity.Error, nameof(Boyfriend),
|
await Log(
|
||||||
|
new LogMessage(
|
||||||
|
LogSeverity.Error, nameof(Boyfriend),
|
||||||
"Exception while ticking guilds", exc));
|
"Exception while ticking guilds", exc));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,10 +118,13 @@ public static class Boyfriend {
|
||||||
var saveData = false;
|
var saveData = false;
|
||||||
_ = int.TryParse(config["EventEarlyNotificationOffset"], out var offset);
|
_ = int.TryParse(config["EventEarlyNotificationOffset"], out var offset);
|
||||||
foreach (var schEvent in guild.Events)
|
foreach (var schEvent in guild.Events)
|
||||||
if (schEvent.Status is GuildScheduledEventStatus.Scheduled && config["AutoStartEvents"] is "true" &&
|
if (schEvent.Status is GuildScheduledEventStatus.Scheduled
|
||||||
DateTimeOffset.Now >= schEvent.StartTime) { await schEvent.StartAsync(); } else if
|
&& config["AutoStartEvents"] is "true"
|
||||||
(!data.EarlyNotifications.Contains(schEvent.Id) &&
|
&& DateTimeOffset
|
||||||
DateTimeOffset.Now >= schEvent.StartTime.Subtract(new TimeSpan(0, offset, 0))) {
|
.Now
|
||||||
|
>= schEvent.StartTime) await schEvent.StartAsync();
|
||||||
|
else if (!data.EarlyNotifications.Contains(schEvent.Id)
|
||||||
|
&& DateTimeOffset.Now >= schEvent.StartTime.Subtract(new TimeSpan(0, offset, 0))) {
|
||||||
data.EarlyNotifications.Add(schEvent.Id);
|
data.EarlyNotifications.Add(schEvent.Id);
|
||||||
var receivers = config["EventStartedReceivers"];
|
var receivers = config["EventStartedReceivers"];
|
||||||
var role = guild.GetRole(ulong.Parse(config["EventNotificationRole"]));
|
var role = guild.GetRole(ulong.Parse(config["EventNotificationRole"]));
|
||||||
|
@ -130,7 +136,8 @@ public static class Boyfriend {
|
||||||
.Where(user => role is null || !((RestGuildUser)user).RoleIds.Contains(role.Id))
|
.Where(user => role is null || !((RestGuildUser)user).RoleIds.Contains(role.Id))
|
||||||
.Aggregate(mentions, (current, user) => current.Append($"{user.Mention} "));
|
.Aggregate(mentions, (current, user) => current.Append($"{user.Mention} "));
|
||||||
|
|
||||||
await Utils.GetEventNotificationChannel(guild)?.SendMessageAsync(string.Format(
|
await Utils.GetEventNotificationChannel(guild)?.SendMessageAsync(
|
||||||
|
string.Format(
|
||||||
Messages.EventEarlyNotification,
|
Messages.EventEarlyNotification,
|
||||||
mentions,
|
mentions,
|
||||||
Utils.Wrap(schEvent.Name),
|
Utils.Wrap(schEvent.Name),
|
||||||
|
@ -140,17 +147,19 @@ public static class Boyfriend {
|
||||||
|
|
||||||
foreach (var mData in data.MemberData.Values) {
|
foreach (var mData in data.MemberData.Values) {
|
||||||
if (DateTimeOffset.Now >= mData.BannedUntil) _ = guild.RemoveBanAsync(mData.Id);
|
if (DateTimeOffset.Now >= mData.BannedUntil) _ = guild.RemoveBanAsync(mData.Id);
|
||||||
|
if (!mData.IsInGuild) continue;
|
||||||
|
|
||||||
if (mData.IsInGuild) {
|
|
||||||
if (DateTimeOffset.Now >= mData.MutedUntil) {
|
if (DateTimeOffset.Now >= mData.MutedUntil) {
|
||||||
await Utils.UnmuteMemberAsync(data, Client.CurrentUser.ToString(), guild.GetUser(mData.Id),
|
await Utils.UnmuteMemberAsync(
|
||||||
|
data, Client.CurrentUser.ToString(), guild.GetUser(mData.Id),
|
||||||
Messages.PunishmentExpired);
|
Messages.PunishmentExpired);
|
||||||
saveData = true;
|
saveData = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = mData.Reminders.Count - 1; i >= 0; i--) {
|
for (var i = mData.Reminders.Count - 1; i >= 0; i--) {
|
||||||
var reminder = mData.Reminders[i];
|
var reminder = mData.Reminders[i];
|
||||||
if (DateTimeOffset.Now >= reminder.RemindAt) {
|
if (DateTimeOffset.Now < reminder.RemindAt) continue;
|
||||||
|
|
||||||
var channel = guild.GetTextChannel(reminder.ReminderChannel);
|
var channel = guild.GetTextChannel(reminder.ReminderChannel);
|
||||||
if (channel is null) {
|
if (channel is null) {
|
||||||
await Utils.SendDirectMessage(Client.GetUser(mData.Id), reminder.ReminderText);
|
await Utils.SendDirectMessage(Client.GetUser(mData.Id), reminder.ReminderText);
|
||||||
|
@ -163,8 +172,6 @@ public static class Boyfriend {
|
||||||
saveData = true;
|
saveData = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (saveData) data.Save(true).Wait();
|
if (saveData) data.Save(true).Wait();
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,9 @@ public sealed class CommandProcessor {
|
||||||
|
|
||||||
try { Task.WaitAll(_tasks.ToArray()); } catch (AggregateException e) {
|
try { Task.WaitAll(_tasks.ToArray()); } catch (AggregateException e) {
|
||||||
foreach (var ex in e.InnerExceptions)
|
foreach (var ex in e.InnerExceptions)
|
||||||
await Boyfriend.Log(new LogMessage(LogSeverity.Error, nameof(CommandProcessor),
|
await Boyfriend.Log(
|
||||||
|
new LogMessage(
|
||||||
|
LogSeverity.Error, nameof(CommandProcessor),
|
||||||
"Exception while executing commands", ex));
|
"Exception while executing commands", ex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +76,8 @@ public sealed class CommandProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reply(string response, string? customEmoji = null) {
|
public void Reply(string response, string? customEmoji = null) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{customEmoji ?? ReplyEmojis.Success} {response}",
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage, $"{customEmoji ?? ReplyEmojis.Success} {response}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,15 +94,18 @@ public sealed class CommandProcessor {
|
||||||
_ = Context.Message.ReplyAsync(_stackedReplyMessage.ToString(), false, null, AllowedMentions.None);
|
_ = Context.Message.ReplyAsync(_stackedReplyMessage.ToString(), false, null, AllowedMentions.None);
|
||||||
|
|
||||||
var data = GuildData.Get(Context.Guild);
|
var data = GuildData.Get(Context.Guild);
|
||||||
var adminChannel = data.PublicFeedbackChannel;
|
var adminChannel = data.PrivateFeedbackChannel;
|
||||||
var systemChannel = data.PrivateFeedbackChannel;
|
var systemChannel = data.PublicFeedbackChannel;
|
||||||
if (_stackedPrivateFeedback.Length > 0 && adminChannel is not null &&
|
if (_stackedPrivateFeedback.Length > 0
|
||||||
adminChannel.Id != Context.Message.Channel.Id) {
|
&& adminChannel is not null
|
||||||
|
&& adminChannel.Id != Context.Message.Channel.Id) {
|
||||||
_ = Utils.SilentSendAsync(adminChannel, _stackedPrivateFeedback.ToString());
|
_ = Utils.SilentSendAsync(adminChannel, _stackedPrivateFeedback.ToString());
|
||||||
_stackedPrivateFeedback.Clear();
|
_stackedPrivateFeedback.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_stackedPublicFeedback.Length > 0 && systemChannel is not null && systemChannel.Id != adminChannel?.Id
|
if (_stackedPublicFeedback.Length > 0
|
||||||
|
&& systemChannel is not null
|
||||||
|
&& systemChannel.Id != adminChannel?.Id
|
||||||
&& systemChannel.Id != Context.Message.Channel.Id) {
|
&& systemChannel.Id != Context.Message.Channel.Id) {
|
||||||
_ = Utils.SilentSendAsync(systemChannel, _stackedPublicFeedback.ToString());
|
_ = Utils.SilentSendAsync(systemChannel, _stackedPublicFeedback.ToString());
|
||||||
_stackedPublicFeedback.Clear();
|
_stackedPublicFeedback.Clear();
|
||||||
|
@ -108,7 +114,8 @@ public sealed class CommandProcessor {
|
||||||
|
|
||||||
public string? GetRemaining(string[] from, int startIndex, string? argument) {
|
public string? GetRemaining(string[] from, int startIndex, string? argument) {
|
||||||
if (startIndex >= from.Length && argument is not null)
|
if (startIndex >= from.Length && argument is not null)
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage,
|
||||||
$"{ReplyEmojis.MissingArgument} {Utils.GetMessage($"Missing{argument}")}", Context.Message);
|
$"{ReplyEmojis.MissingArgument} {Utils.GetMessage($"Missing{argument}")}", Context.Message);
|
||||||
else return string.Join(" ", from, startIndex, from.Length - startIndex);
|
else return string.Join(" ", from, startIndex, from.Length - startIndex);
|
||||||
return null;
|
return null;
|
||||||
|
@ -116,14 +123,16 @@ public sealed class CommandProcessor {
|
||||||
|
|
||||||
public Tuple<ulong, SocketUser?>? GetUser(string[] args, string[] cleanArgs, int index) {
|
public Tuple<ulong, SocketUser?>? GetUser(string[] args, string[] cleanArgs, int index) {
|
||||||
if (index >= args.Length) {
|
if (index >= args.Length) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingUser}",
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingUser}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mention = Utils.ParseMention(args[index]);
|
var mention = Utils.ParseMention(args[index]);
|
||||||
if (mention is 0) {
|
if (mention is 0) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage,
|
||||||
$"{ReplyEmojis.InvalidArgument} {string.Format(Messages.InvalidUser, Utils.Wrap(cleanArgs[index]))}",
|
$"{ReplyEmojis.InvalidArgument} {string.Format(Messages.InvalidUser, Utils.Wrap(cleanArgs[index]))}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return null;
|
return null;
|
||||||
|
@ -131,7 +140,8 @@ public sealed class CommandProcessor {
|
||||||
|
|
||||||
var exists = Utils.UserExists(mention);
|
var exists = Utils.UserExists(mention);
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage,
|
||||||
$"{ReplyEmojis.Error} {string.Format(Messages.UserNotFound, Utils.Wrap(cleanArgs[index]))}",
|
$"{ReplyEmojis.Error} {string.Format(Messages.UserNotFound, Utils.Wrap(cleanArgs[index]))}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return null;
|
return null;
|
||||||
|
@ -142,7 +152,8 @@ public sealed class CommandProcessor {
|
||||||
|
|
||||||
public bool HasPermission(GuildPermission permission) {
|
public bool HasPermission(GuildPermission permission) {
|
||||||
if (!Context.Guild.CurrentUser.GuildPermissions.Has(permission)) {
|
if (!Context.Guild.CurrentUser.GuildPermissions.Has(permission)) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage,
|
||||||
$"{ReplyEmojis.NoPermission} {Utils.GetMessage($"BotCannot{permission}")}",
|
$"{ReplyEmojis.NoPermission} {Utils.GetMessage($"BotCannot{permission}")}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return false;
|
return false;
|
||||||
|
@ -150,7 +161,8 @@ public sealed class CommandProcessor {
|
||||||
|
|
||||||
if (!GetMember().GuildPermissions.Has(permission)
|
if (!GetMember().GuildPermissions.Has(permission)
|
||||||
&& Context.Guild.OwnerId != Context.User.Id) {
|
&& Context.Guild.OwnerId != Context.User.Id) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage,
|
||||||
$"{ReplyEmojis.NoPermission} {Utils.GetMessage($"UserCannot{permission}")}",
|
$"{ReplyEmojis.NoPermission} {Utils.GetMessage($"UserCannot{permission}")}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return false;
|
return false;
|
||||||
|
@ -169,14 +181,16 @@ public sealed class CommandProcessor {
|
||||||
|
|
||||||
public SocketGuildUser? GetMember(string[] args, int index) {
|
public SocketGuildUser? GetMember(string[] args, int index) {
|
||||||
if (index >= args.Length) {
|
if (index >= args.Length) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingMember}",
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingMember}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var member = Context.Guild.GetUser(Utils.ParseMention(args[index]));
|
var member = Context.Guild.GetUser(Utils.ParseMention(args[index]));
|
||||||
if (member is null)
|
if (member is null)
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage,
|
||||||
$"{ReplyEmojis.InvalidArgument} {Messages.InvalidMember}",
|
$"{ReplyEmojis.InvalidArgument} {Messages.InvalidMember}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return member;
|
return member;
|
||||||
|
@ -184,7 +198,8 @@ public sealed class CommandProcessor {
|
||||||
|
|
||||||
public ulong? GetBan(string[] args, int index) {
|
public ulong? GetBan(string[] args, int index) {
|
||||||
if (index >= args.Length) {
|
if (index >= args.Length) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingUser}",
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingUser}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -200,14 +215,16 @@ public sealed class CommandProcessor {
|
||||||
|
|
||||||
public int? GetNumberRange(string[] args, int index, int min, int max, string? argument) {
|
public int? GetNumberRange(string[] args, int index, int min, int max, string? argument) {
|
||||||
if (index >= args.Length) {
|
if (index >= args.Length) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage,
|
||||||
$"{ReplyEmojis.MissingArgument} {string.Format(Messages.MissingNumber, min.ToString(), max.ToString())}",
|
$"{ReplyEmojis.MissingArgument} {string.Format(Messages.MissingNumber, min.ToString(), max.ToString())}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!int.TryParse(args[index], out var i)) {
|
if (!int.TryParse(args[index], out var i)) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage,
|
||||||
$"{ReplyEmojis.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}Invalid"), min.ToString(), max.ToString(), Utils.Wrap(args[index]))}",
|
$"{ReplyEmojis.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}Invalid"), min.ToString(), max.ToString(), Utils.Wrap(args[index]))}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return null;
|
return null;
|
||||||
|
@ -215,14 +232,16 @@ public sealed class CommandProcessor {
|
||||||
|
|
||||||
if (argument is null) return i;
|
if (argument is null) return i;
|
||||||
if (i < min) {
|
if (i < min) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage,
|
||||||
$"{ReplyEmojis.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}TooSmall"), min.ToString())}",
|
$"{ReplyEmojis.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}TooSmall"), min.ToString())}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i > max) {
|
if (i > max) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage,
|
||||||
$"{ReplyEmojis.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}TooLarge"), max.ToString())}",
|
$"{ReplyEmojis.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}TooLarge"), max.ToString())}",
|
||||||
Context.Message);
|
Context.Message);
|
||||||
return null;
|
return null;
|
||||||
|
@ -267,31 +286,36 @@ public sealed class CommandProcessor {
|
||||||
|
|
||||||
public bool CanInteractWith(SocketGuildUser user, string action) {
|
public bool CanInteractWith(SocketGuildUser user, string action) {
|
||||||
if (Context.User.Id == user.Id) {
|
if (Context.User.Id == user.Id) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage,
|
||||||
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Themselves")}", Context.Message);
|
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Themselves")}", Context.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Context.Guild.CurrentUser.Id == user.Id) {
|
if (Context.Guild.CurrentUser.Id == user.Id) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage,
|
||||||
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Bot")}", Context.Message);
|
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Bot")}", Context.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Context.Guild.Owner.Id == user.Id) {
|
if (Context.Guild.Owner.Id == user.Id) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage,
|
||||||
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Owner")}", Context.Message);
|
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Owner")}", Context.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Context.Guild.CurrentUser.Hierarchy <= user.Hierarchy) {
|
if (Context.Guild.CurrentUser.Hierarchy <= user.Hierarchy) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage,
|
||||||
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"BotCannot{action}Target")}", Context.Message);
|
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"BotCannot{action}Target")}", Context.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Context.Guild.Owner.Id != Context.User.Id && GetMember().Hierarchy <= user.Hierarchy) {
|
if (Context.Guild.Owner.Id != Context.User.Id && GetMember().Hierarchy <= user.Hierarchy) {
|
||||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
Utils.SafeAppendToBuilder(
|
||||||
|
_stackedReplyMessage,
|
||||||
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Target")}", Context.Message);
|
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Target")}", Context.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,11 +49,13 @@ public static class EventHandler {
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task MessageDeletedEvent(Cacheable<IMessage, ulong> message,
|
private static async Task MessageDeletedEvent(
|
||||||
|
Cacheable<IMessage, ulong> message,
|
||||||
Cacheable<IMessageChannel, ulong> channel) {
|
Cacheable<IMessageChannel, ulong> channel) {
|
||||||
var msg = message.Value;
|
var msg = message.Value;
|
||||||
if (channel.Value is not SocketGuildChannel gChannel || msg is null or ISystemMessage ||
|
if (channel.Value is not SocketGuildChannel gChannel
|
||||||
msg.Author.IsBot) return;
|
|| msg is null or ISystemMessage
|
||||||
|
|| msg.Author.IsBot) return;
|
||||||
|
|
||||||
var guild = gChannel.Guild;
|
var guild = gChannel.Guild;
|
||||||
|
|
||||||
|
@ -64,11 +66,14 @@ public static class EventHandler {
|
||||||
await Task.Delay(500);
|
await Task.Delay(500);
|
||||||
|
|
||||||
var auditLogEntry = (await guild.GetAuditLogsAsync(1).FlattenAsync()).First();
|
var auditLogEntry = (await guild.GetAuditLogsAsync(1).FlattenAsync()).First();
|
||||||
if (auditLogEntry.CreatedAt >= DateTimeOffset.Now.Subtract(TimeSpan.FromSeconds(1)) &&
|
if (auditLogEntry.CreatedAt >= DateTimeOffset.Now.Subtract(TimeSpan.FromSeconds(1))
|
||||||
auditLogEntry.Data is MessageDeleteAuditLogData data && msg.Author.Id == data.Target.Id)
|
&& auditLogEntry.Data is MessageDeleteAuditLogData data
|
||||||
|
&& msg.Author.Id == data.Target.Id)
|
||||||
mention = auditLogEntry.User.Mention;
|
mention = auditLogEntry.User.Mention;
|
||||||
|
|
||||||
await Utils.SendFeedbackAsync(string.Format(Messages.CachedMessageDeleted, msg.Author.Mention,
|
await Utils.SendFeedbackAsync(
|
||||||
|
string.Format(
|
||||||
|
Messages.CachedMessageDeleted, msg.Author.Mention,
|
||||||
Utils.MentionChannel(channel.Id),
|
Utils.MentionChannel(channel.Id),
|
||||||
Utils.Wrap(msg.CleanContent)), guild, mention);
|
Utils.Wrap(msg.CleanContent)), guild, mention);
|
||||||
}
|
}
|
||||||
|
@ -87,18 +92,23 @@ public static class EventHandler {
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task MessageUpdatedEvent(Cacheable<IMessage, ulong> messageCached, IMessage messageSocket,
|
private static async Task MessageUpdatedEvent(
|
||||||
|
Cacheable<IMessage, ulong> messageCached, IMessage messageSocket,
|
||||||
ISocketMessageChannel channel) {
|
ISocketMessageChannel channel) {
|
||||||
var msg = messageCached.Value;
|
var msg = messageCached.Value;
|
||||||
if (channel is not SocketGuildChannel gChannel || msg is null or ISystemMessage ||
|
if (channel is not SocketGuildChannel gChannel
|
||||||
msg.CleanContent == messageSocket.CleanContent || msg.Author.IsBot) return;
|
|| msg is null or ISystemMessage
|
||||||
|
|| msg.CleanContent == messageSocket.CleanContent
|
||||||
|
|| msg.Author.IsBot) return;
|
||||||
|
|
||||||
var guild = gChannel.Guild;
|
var guild = gChannel.Guild;
|
||||||
Utils.SetCurrentLanguage(guild);
|
Utils.SetCurrentLanguage(guild);
|
||||||
|
|
||||||
var isLimitedSpace = msg.CleanContent.Length + messageSocket.CleanContent.Length < 1940;
|
var isLimitedSpace = msg.CleanContent.Length + messageSocket.CleanContent.Length < 1940;
|
||||||
|
|
||||||
await Utils.SendFeedbackAsync(string.Format(Messages.CachedMessageEdited, Utils.MentionChannel(channel.Id),
|
await Utils.SendFeedbackAsync(
|
||||||
|
string.Format(
|
||||||
|
Messages.CachedMessageEdited, Utils.MentionChannel(channel.Id),
|
||||||
Utils.Wrap(msg.CleanContent, isLimitedSpace), Utils.Wrap(messageSocket.CleanContent, isLimitedSpace)),
|
Utils.Wrap(msg.CleanContent, isLimitedSpace), Utils.Wrap(messageSocket.CleanContent, isLimitedSpace)),
|
||||||
guild, msg.Author.Mention);
|
guild, msg.Author.Mention);
|
||||||
}
|
}
|
||||||
|
@ -111,8 +121,10 @@ public static class EventHandler {
|
||||||
Utils.SetCurrentLanguage(guild);
|
Utils.SetCurrentLanguage(guild);
|
||||||
|
|
||||||
if (config["SendWelcomeMessages"] is "true" && data.PublicFeedbackChannel is not null)
|
if (config["SendWelcomeMessages"] is "true" && data.PublicFeedbackChannel is not null)
|
||||||
await Utils.SilentSendAsync(data.PublicFeedbackChannel,
|
await Utils.SilentSendAsync(
|
||||||
string.Format(config["WelcomeMessage"] is "default"
|
data.PublicFeedbackChannel,
|
||||||
|
string.Format(
|
||||||
|
config["WelcomeMessage"] is "default"
|
||||||
? Messages.DefaultWelcomeMessage
|
? Messages.DefaultWelcomeMessage
|
||||||
: config["WelcomeMessage"], user.Mention, guild.Name));
|
: config["WelcomeMessage"], user.Mention, guild.Name));
|
||||||
|
|
||||||
|
@ -148,8 +160,8 @@ public static class EventHandler {
|
||||||
var eventConfig = GuildData.Get(guild).Preferences;
|
var eventConfig = GuildData.Get(guild).Preferences;
|
||||||
var channel = Utils.GetEventNotificationChannel(guild);
|
var channel = Utils.GetEventNotificationChannel(guild);
|
||||||
Utils.SetCurrentLanguage(guild);
|
Utils.SetCurrentLanguage(guild);
|
||||||
|
if (channel is null) return;
|
||||||
|
|
||||||
if (channel is not null) {
|
|
||||||
var role = guild.GetRole(ulong.Parse(eventConfig["EventNotificationRole"]));
|
var role = guild.GetRole(ulong.Parse(eventConfig["EventNotificationRole"]));
|
||||||
var mentions = role is not null
|
var mentions = role is not null
|
||||||
? $"{role.Mention} {scheduledEvent.Creator.Mention}"
|
? $"{role.Mention} {scheduledEvent.Creator.Mention}"
|
||||||
|
@ -159,13 +171,14 @@ public static class EventHandler {
|
||||||
var descAndLink
|
var descAndLink
|
||||||
= $"\n{Utils.Wrap(scheduledEvent.Description)}\nhttps://discord.com/events/{guild.Id}/{scheduledEvent.Id}";
|
= $"\n{Utils.Wrap(scheduledEvent.Description)}\nhttps://discord.com/events/{guild.Id}/{scheduledEvent.Id}";
|
||||||
|
|
||||||
await Utils.SilentSendAsync(channel,
|
await Utils.SilentSendAsync(
|
||||||
string.Format(Messages.EventCreated, mentions,
|
channel,
|
||||||
|
string.Format(
|
||||||
|
Messages.EventCreated, mentions,
|
||||||
Utils.Wrap(scheduledEvent.Name), location,
|
Utils.Wrap(scheduledEvent.Name), location,
|
||||||
scheduledEvent.StartTime.ToUnixTimeSeconds().ToString(), descAndLink),
|
scheduledEvent.StartTime.ToUnixTimeSeconds().ToString(), descAndLink),
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task ScheduledEventCancelledEvent(SocketGuildEvent scheduledEvent) {
|
private static async Task ScheduledEventCancelledEvent(SocketGuildEvent scheduledEvent) {
|
||||||
var guild = scheduledEvent.Guild;
|
var guild = scheduledEvent.Guild;
|
||||||
|
@ -173,7 +186,9 @@ public static class EventHandler {
|
||||||
var channel = Utils.GetEventNotificationChannel(guild);
|
var channel = Utils.GetEventNotificationChannel(guild);
|
||||||
Utils.SetCurrentLanguage(guild);
|
Utils.SetCurrentLanguage(guild);
|
||||||
if (channel is not null)
|
if (channel is not null)
|
||||||
await channel.SendMessageAsync(string.Format(Messages.EventCancelled, Utils.Wrap(scheduledEvent.Name),
|
await channel.SendMessageAsync(
|
||||||
|
string.Format(
|
||||||
|
Messages.EventCancelled, Utils.Wrap(scheduledEvent.Name),
|
||||||
eventConfig["FrowningFace"] is "true" ? $" {Messages.SettingsFrowningFace}" : ""));
|
eventConfig["FrowningFace"] is "true" ? $" {Messages.SettingsFrowningFace}" : ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +198,8 @@ public static class EventHandler {
|
||||||
var channel = Utils.GetEventNotificationChannel(guild);
|
var channel = Utils.GetEventNotificationChannel(guild);
|
||||||
Utils.SetCurrentLanguage(guild);
|
Utils.SetCurrentLanguage(guild);
|
||||||
|
|
||||||
if (channel is not null) {
|
if (channel is null) return;
|
||||||
|
|
||||||
var receivers = eventConfig["EventStartedReceivers"];
|
var receivers = eventConfig["EventStartedReceivers"];
|
||||||
var role = guild.GetRole(ulong.Parse(eventConfig["EventNotificationRole"]));
|
var role = guild.GetRole(ulong.Parse(eventConfig["EventNotificationRole"]));
|
||||||
var mentions = Boyfriend.StringBuilder;
|
var mentions = Boyfriend.StringBuilder;
|
||||||
|
@ -194,19 +210,22 @@ public static class EventHandler {
|
||||||
.Where(user => role is null || !((RestGuildUser)user).RoleIds.Contains(role.Id))
|
.Where(user => role is null || !((RestGuildUser)user).RoleIds.Contains(role.Id))
|
||||||
.Aggregate(mentions, (current, user) => current.Append($"{user.Mention} "));
|
.Aggregate(mentions, (current, user) => current.Append($"{user.Mention} "));
|
||||||
|
|
||||||
await channel.SendMessageAsync(string.Format(Messages.EventStarted, mentions,
|
await channel.SendMessageAsync(
|
||||||
|
string.Format(
|
||||||
|
Messages.EventStarted, mentions,
|
||||||
Utils.Wrap(scheduledEvent.Name),
|
Utils.Wrap(scheduledEvent.Name),
|
||||||
Utils.Wrap(scheduledEvent.Location) ?? Utils.MentionChannel(scheduledEvent.Channel.Id)));
|
Utils.Wrap(scheduledEvent.Location) ?? Utils.MentionChannel(scheduledEvent.Channel.Id)));
|
||||||
mentions.Clear();
|
mentions.Clear();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task ScheduledEventCompletedEvent(SocketGuildEvent scheduledEvent) {
|
private static async Task ScheduledEventCompletedEvent(SocketGuildEvent scheduledEvent) {
|
||||||
var guild = scheduledEvent.Guild;
|
var guild = scheduledEvent.Guild;
|
||||||
var channel = Utils.GetEventNotificationChannel(guild);
|
var channel = Utils.GetEventNotificationChannel(guild);
|
||||||
Utils.SetCurrentLanguage(guild);
|
Utils.SetCurrentLanguage(guild);
|
||||||
if (channel is not null)
|
if (channel is not null)
|
||||||
await channel.SendMessageAsync(string.Format(Messages.EventCompleted, Utils.Wrap(scheduledEvent.Name),
|
await channel.SendMessageAsync(
|
||||||
|
string.Format(
|
||||||
|
Messages.EventCompleted, Utils.Wrap(scheduledEvent.Name),
|
||||||
Utils.GetHumanizedTimeSpan(DateTimeOffset.Now.Subtract(scheduledEvent.StartTime))));
|
Utils.GetHumanizedTimeSpan(DateTimeOffset.Now.Subtract(scheduledEvent.StartTime))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue