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() {
|
||||
MessageCacheSize = 250,
|
||||
GatewayIntents
|
||||
= (GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent | GatewayIntents.GuildMembers) &
|
||||
~GatewayIntents.GuildInvites,
|
||||
= (GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent | GatewayIntents.GuildMembers)
|
||||
& ~GatewayIntents.GuildInvites,
|
||||
AlwaysDownloadUsers = true,
|
||||
AlwaysResolveStickers = false,
|
||||
AlwaysDownloadDefaultStickers = false,
|
||||
|
@ -26,7 +26,8 @@ public static class Boyfriend {
|
|||
private static uint _nextSongIndex;
|
||||
|
||||
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)),
|
||||
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)),
|
||||
|
@ -75,7 +76,9 @@ public static class Boyfriend {
|
|||
|
||||
try { Task.WaitAll(GuildTickTasks.ToArray()); } catch (AggregateException ex) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -115,10 +118,13 @@ public static class Boyfriend {
|
|||
var saveData = false;
|
||||
_ = int.TryParse(config["EventEarlyNotificationOffset"], out var offset);
|
||||
foreach (var schEvent in guild.Events)
|
||||
if (schEvent.Status is GuildScheduledEventStatus.Scheduled && config["AutoStartEvents"] is "true" &&
|
||||
DateTimeOffset.Now >= schEvent.StartTime) { await schEvent.StartAsync(); } else if
|
||||
(!data.EarlyNotifications.Contains(schEvent.Id) &&
|
||||
DateTimeOffset.Now >= schEvent.StartTime.Subtract(new TimeSpan(0, offset, 0))) {
|
||||
if (schEvent.Status is GuildScheduledEventStatus.Scheduled
|
||||
&& config["AutoStartEvents"] is "true"
|
||||
&& DateTimeOffset
|
||||
.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);
|
||||
var receivers = config["EventStartedReceivers"];
|
||||
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))
|
||||
.Aggregate(mentions, (current, user) => current.Append($"{user.Mention} "));
|
||||
|
||||
await Utils.GetEventNotificationChannel(guild)?.SendMessageAsync(string.Format(
|
||||
await Utils.GetEventNotificationChannel(guild)?.SendMessageAsync(
|
||||
string.Format(
|
||||
Messages.EventEarlyNotification,
|
||||
mentions,
|
||||
Utils.Wrap(schEvent.Name),
|
||||
|
@ -140,17 +147,19 @@ public static class Boyfriend {
|
|||
|
||||
foreach (var mData in data.MemberData.Values) {
|
||||
if (DateTimeOffset.Now >= mData.BannedUntil) _ = guild.RemoveBanAsync(mData.Id);
|
||||
if (!mData.IsInGuild) continue;
|
||||
|
||||
if (mData.IsInGuild) {
|
||||
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);
|
||||
saveData = true;
|
||||
}
|
||||
|
||||
for (var i = mData.Reminders.Count - 1; i >= 0; i--) {
|
||||
var reminder = mData.Reminders[i];
|
||||
if (DateTimeOffset.Now >= reminder.RemindAt) {
|
||||
if (DateTimeOffset.Now < reminder.RemindAt) continue;
|
||||
|
||||
var channel = guild.GetTextChannel(reminder.ReminderChannel);
|
||||
if (channel is null) {
|
||||
await Utils.SendDirectMessage(Client.GetUser(mData.Id), reminder.ReminderText);
|
||||
|
@ -163,8 +172,6 @@ public static class Boyfriend {
|
|||
saveData = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (saveData) data.Save(true).Wait();
|
||||
}
|
||||
|
|
|
@ -47,7 +47,9 @@ public sealed class CommandProcessor {
|
|||
|
||||
try { Task.WaitAll(_tasks.ToArray()); } catch (AggregateException e) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -74,7 +76,8 @@ public sealed class CommandProcessor {
|
|||
}
|
||||
|
||||
public void Reply(string response, string? customEmoji = null) {
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{customEmoji ?? ReplyEmojis.Success} {response}",
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage, $"{customEmoji ?? ReplyEmojis.Success} {response}",
|
||||
Context.Message);
|
||||
}
|
||||
|
||||
|
@ -91,15 +94,18 @@ public sealed class CommandProcessor {
|
|||
_ = Context.Message.ReplyAsync(_stackedReplyMessage.ToString(), false, null, AllowedMentions.None);
|
||||
|
||||
var data = GuildData.Get(Context.Guild);
|
||||
var adminChannel = data.PublicFeedbackChannel;
|
||||
var systemChannel = data.PrivateFeedbackChannel;
|
||||
if (_stackedPrivateFeedback.Length > 0 && adminChannel is not null &&
|
||||
adminChannel.Id != Context.Message.Channel.Id) {
|
||||
var adminChannel = data.PrivateFeedbackChannel;
|
||||
var systemChannel = data.PublicFeedbackChannel;
|
||||
if (_stackedPrivateFeedback.Length > 0
|
||||
&& adminChannel is not null
|
||||
&& adminChannel.Id != Context.Message.Channel.Id) {
|
||||
_ = Utils.SilentSendAsync(adminChannel, _stackedPrivateFeedback.ToString());
|
||||
_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) {
|
||||
_ = Utils.SilentSendAsync(systemChannel, _stackedPublicFeedback.ToString());
|
||||
_stackedPublicFeedback.Clear();
|
||||
|
@ -108,7 +114,8 @@ public sealed class CommandProcessor {
|
|||
|
||||
public string? GetRemaining(string[] from, int startIndex, string? argument) {
|
||||
if (startIndex >= from.Length && argument is not null)
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage,
|
||||
$"{ReplyEmojis.MissingArgument} {Utils.GetMessage($"Missing{argument}")}", Context.Message);
|
||||
else return string.Join(" ", from, startIndex, from.Length - startIndex);
|
||||
return null;
|
||||
|
@ -116,14 +123,16 @@ public sealed class CommandProcessor {
|
|||
|
||||
public Tuple<ulong, SocketUser?>? GetUser(string[] args, string[] cleanArgs, int index) {
|
||||
if (index >= args.Length) {
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingUser}",
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingUser}",
|
||||
Context.Message);
|
||||
return null;
|
||||
}
|
||||
|
||||
var mention = Utils.ParseMention(args[index]);
|
||||
if (mention is 0) {
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage,
|
||||
$"{ReplyEmojis.InvalidArgument} {string.Format(Messages.InvalidUser, Utils.Wrap(cleanArgs[index]))}",
|
||||
Context.Message);
|
||||
return null;
|
||||
|
@ -131,7 +140,8 @@ public sealed class CommandProcessor {
|
|||
|
||||
var exists = Utils.UserExists(mention);
|
||||
if (!exists) {
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage,
|
||||
$"{ReplyEmojis.Error} {string.Format(Messages.UserNotFound, Utils.Wrap(cleanArgs[index]))}",
|
||||
Context.Message);
|
||||
return null;
|
||||
|
@ -142,7 +152,8 @@ public sealed class CommandProcessor {
|
|||
|
||||
public bool HasPermission(GuildPermission permission) {
|
||||
if (!Context.Guild.CurrentUser.GuildPermissions.Has(permission)) {
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage,
|
||||
$"{ReplyEmojis.NoPermission} {Utils.GetMessage($"BotCannot{permission}")}",
|
||||
Context.Message);
|
||||
return false;
|
||||
|
@ -150,7 +161,8 @@ public sealed class CommandProcessor {
|
|||
|
||||
if (!GetMember().GuildPermissions.Has(permission)
|
||||
&& Context.Guild.OwnerId != Context.User.Id) {
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage,
|
||||
$"{ReplyEmojis.NoPermission} {Utils.GetMessage($"UserCannot{permission}")}",
|
||||
Context.Message);
|
||||
return false;
|
||||
|
@ -169,14 +181,16 @@ public sealed class CommandProcessor {
|
|||
|
||||
public SocketGuildUser? GetMember(string[] args, int index) {
|
||||
if (index >= args.Length) {
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingMember}",
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingMember}",
|
||||
Context.Message);
|
||||
return null;
|
||||
}
|
||||
|
||||
var member = Context.Guild.GetUser(Utils.ParseMention(args[index]));
|
||||
if (member is null)
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage,
|
||||
$"{ReplyEmojis.InvalidArgument} {Messages.InvalidMember}",
|
||||
Context.Message);
|
||||
return member;
|
||||
|
@ -184,7 +198,8 @@ public sealed class CommandProcessor {
|
|||
|
||||
public ulong? GetBan(string[] args, int index) {
|
||||
if (index >= args.Length) {
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingUser}",
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage, $"{ReplyEmojis.MissingArgument} {Messages.MissingUser}",
|
||||
Context.Message);
|
||||
return null;
|
||||
}
|
||||
|
@ -200,14 +215,16 @@ public sealed class CommandProcessor {
|
|||
|
||||
public int? GetNumberRange(string[] args, int index, int min, int max, string? argument) {
|
||||
if (index >= args.Length) {
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage,
|
||||
$"{ReplyEmojis.MissingArgument} {string.Format(Messages.MissingNumber, min.ToString(), max.ToString())}",
|
||||
Context.Message);
|
||||
return null;
|
||||
}
|
||||
|
||||
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]))}",
|
||||
Context.Message);
|
||||
return null;
|
||||
|
@ -215,14 +232,16 @@ public sealed class CommandProcessor {
|
|||
|
||||
if (argument is null) return i;
|
||||
if (i < min) {
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage,
|
||||
$"{ReplyEmojis.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}TooSmall"), min.ToString())}",
|
||||
Context.Message);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (i > max) {
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage,
|
||||
$"{ReplyEmojis.InvalidArgument} {string.Format(Utils.GetMessage($"{argument}TooLarge"), max.ToString())}",
|
||||
Context.Message);
|
||||
return null;
|
||||
|
@ -267,31 +286,36 @@ public sealed class CommandProcessor {
|
|||
|
||||
public bool CanInteractWith(SocketGuildUser user, string action) {
|
||||
if (Context.User.Id == user.Id) {
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage,
|
||||
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Themselves")}", Context.Message);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Context.Guild.CurrentUser.Id == user.Id) {
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage,
|
||||
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Bot")}", Context.Message);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Context.Guild.Owner.Id == user.Id) {
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage,
|
||||
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"UserCannot{action}Owner")}", Context.Message);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Context.Guild.CurrentUser.Hierarchy <= user.Hierarchy) {
|
||||
Utils.SafeAppendToBuilder(_stackedReplyMessage,
|
||||
Utils.SafeAppendToBuilder(
|
||||
_stackedReplyMessage,
|
||||
$"{ReplyEmojis.CantInteract} {Utils.GetMessage($"BotCannot{action}Target")}", Context.Message);
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -49,11 +49,13 @@ public static class EventHandler {
|
|||
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) {
|
||||
var msg = message.Value;
|
||||
if (channel.Value is not SocketGuildChannel gChannel || msg is null or ISystemMessage ||
|
||||
msg.Author.IsBot) return;
|
||||
if (channel.Value is not SocketGuildChannel gChannel
|
||||
|| msg is null or ISystemMessage
|
||||
|| msg.Author.IsBot) return;
|
||||
|
||||
var guild = gChannel.Guild;
|
||||
|
||||
|
@ -64,11 +66,14 @@ public static class EventHandler {
|
|||
await Task.Delay(500);
|
||||
|
||||
var auditLogEntry = (await guild.GetAuditLogsAsync(1).FlattenAsync()).First();
|
||||
if (auditLogEntry.CreatedAt >= DateTimeOffset.Now.Subtract(TimeSpan.FromSeconds(1)) &&
|
||||
auditLogEntry.Data is MessageDeleteAuditLogData data && msg.Author.Id == data.Target.Id)
|
||||
if (auditLogEntry.CreatedAt >= DateTimeOffset.Now.Subtract(TimeSpan.FromSeconds(1))
|
||||
&& auditLogEntry.Data is MessageDeleteAuditLogData data
|
||||
&& msg.Author.Id == data.Target.Id)
|
||||
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.Wrap(msg.CleanContent)), guild, mention);
|
||||
}
|
||||
|
@ -87,18 +92,23 @@ public static class EventHandler {
|
|||
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) {
|
||||
var msg = messageCached.Value;
|
||||
if (channel is not SocketGuildChannel gChannel || msg is null or ISystemMessage ||
|
||||
msg.CleanContent == messageSocket.CleanContent || msg.Author.IsBot) return;
|
||||
if (channel is not SocketGuildChannel gChannel
|
||||
|| msg is null or ISystemMessage
|
||||
|| msg.CleanContent == messageSocket.CleanContent
|
||||
|| msg.Author.IsBot) return;
|
||||
|
||||
var guild = gChannel.Guild;
|
||||
Utils.SetCurrentLanguage(guild);
|
||||
|
||||
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)),
|
||||
guild, msg.Author.Mention);
|
||||
}
|
||||
|
@ -111,8 +121,10 @@ public static class EventHandler {
|
|||
Utils.SetCurrentLanguage(guild);
|
||||
|
||||
if (config["SendWelcomeMessages"] is "true" && data.PublicFeedbackChannel is not null)
|
||||
await Utils.SilentSendAsync(data.PublicFeedbackChannel,
|
||||
string.Format(config["WelcomeMessage"] is "default"
|
||||
await Utils.SilentSendAsync(
|
||||
data.PublicFeedbackChannel,
|
||||
string.Format(
|
||||
config["WelcomeMessage"] is "default"
|
||||
? Messages.DefaultWelcomeMessage
|
||||
: config["WelcomeMessage"], user.Mention, guild.Name));
|
||||
|
||||
|
@ -148,8 +160,8 @@ public static class EventHandler {
|
|||
var eventConfig = GuildData.Get(guild).Preferences;
|
||||
var channel = Utils.GetEventNotificationChannel(guild);
|
||||
Utils.SetCurrentLanguage(guild);
|
||||
if (channel is null) return;
|
||||
|
||||
if (channel is not null) {
|
||||
var role = guild.GetRole(ulong.Parse(eventConfig["EventNotificationRole"]));
|
||||
var mentions = role is not null
|
||||
? $"{role.Mention} {scheduledEvent.Creator.Mention}"
|
||||
|
@ -159,13 +171,14 @@ public static class EventHandler {
|
|||
var descAndLink
|
||||
= $"\n{Utils.Wrap(scheduledEvent.Description)}\nhttps://discord.com/events/{guild.Id}/{scheduledEvent.Id}";
|
||||
|
||||
await Utils.SilentSendAsync(channel,
|
||||
string.Format(Messages.EventCreated, mentions,
|
||||
await Utils.SilentSendAsync(
|
||||
channel,
|
||||
string.Format(
|
||||
Messages.EventCreated, mentions,
|
||||
Utils.Wrap(scheduledEvent.Name), location,
|
||||
scheduledEvent.StartTime.ToUnixTimeSeconds().ToString(), descAndLink),
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task ScheduledEventCancelledEvent(SocketGuildEvent scheduledEvent) {
|
||||
var guild = scheduledEvent.Guild;
|
||||
|
@ -173,7 +186,9 @@ public static class EventHandler {
|
|||
var channel = Utils.GetEventNotificationChannel(guild);
|
||||
Utils.SetCurrentLanguage(guild);
|
||||
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}" : ""));
|
||||
}
|
||||
|
||||
|
@ -183,7 +198,8 @@ public static class EventHandler {
|
|||
var channel = Utils.GetEventNotificationChannel(guild);
|
||||
Utils.SetCurrentLanguage(guild);
|
||||
|
||||
if (channel is not null) {
|
||||
if (channel is null) return;
|
||||
|
||||
var receivers = eventConfig["EventStartedReceivers"];
|
||||
var role = guild.GetRole(ulong.Parse(eventConfig["EventNotificationRole"]));
|
||||
var mentions = Boyfriend.StringBuilder;
|
||||
|
@ -194,19 +210,22 @@ public static class EventHandler {
|
|||
.Where(user => role is null || !((RestGuildUser)user).RoleIds.Contains(role.Id))
|
||||
.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.Location) ?? Utils.MentionChannel(scheduledEvent.Channel.Id)));
|
||||
mentions.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task ScheduledEventCompletedEvent(SocketGuildEvent scheduledEvent) {
|
||||
var guild = scheduledEvent.Guild;
|
||||
var channel = Utils.GetEventNotificationChannel(guild);
|
||||
Utils.SetCurrentLanguage(guild);
|
||||
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))));
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue