mirror of
https://github.com/RPCS3/discord-bot.git
synced 2024-11-23 10:19:39 +00:00
add handler to automatically post log uploading instructions in #help
This commit is contained in:
parent
9adfba5ed9
commit
9c693cfb93
55
CompatBot/EventHandlers/PostLogHelpHandler.cs
Normal file
55
CompatBot/EventHandlers/PostLogHelpHandler.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CompatBot.Utils;
|
||||
using DSharpPlus.EventArgs;
|
||||
|
||||
namespace CompatBot.EventHandlers
|
||||
{
|
||||
internal sealed class PostLogHelpHandler
|
||||
{
|
||||
private const RegexOptions DefaultOptions = RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.ExplicitCapture;
|
||||
private static readonly Regex UploadLogMention = new Regex(@"\b(post|upload)\s+(a|the|rpcs3('s)?|your|you're|ur|my)?\blogs?\b", DefaultOptions);
|
||||
private static readonly SemaphoreSlim TheDoor = new SemaphoreSlim(1, 1);
|
||||
private static readonly TimeSpan ThrottlingThreshold = TimeSpan.FromSeconds(5);
|
||||
private static DateTime lastMention = DateTime.UtcNow.AddHours(-1);
|
||||
|
||||
public static async Task OnMessageCreated(MessageCreateEventArgs args)
|
||||
{
|
||||
if (args.Author.IsBot)
|
||||
return;
|
||||
|
||||
if (!args.Channel.Name.Equals("help", StringComparison.InvariantCultureIgnoreCase))
|
||||
return;
|
||||
|
||||
if (DateTime.UtcNow - lastMention < ThrottlingThreshold)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(args.Message.Content) || args.Message.Content.StartsWith(Config.CommandPrefix))
|
||||
return;
|
||||
|
||||
if (!UploadLogMention.IsMatch(args.Message.Content))
|
||||
return;
|
||||
|
||||
if (!TheDoor.Wait(0))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var lastBotMessages = await args.Channel.GetMessagesBeforeAsync(args.Message.Id, 20, DateTime.UtcNow.AddSeconds(-30)).ConfigureAwait(false);
|
||||
foreach (var msg in lastBotMessages)
|
||||
if (BotShutupHandler.NeedToSilence(msg).needToChill)
|
||||
return;
|
||||
|
||||
await args.Channel.SendMessageAsync("To upload log, completely close RPCS3 then drag and drop rpcs3.log.gz from the RPCS3 folder into Discord. The file may have a zip or rar icon.").ConfigureAwait(false);
|
||||
lastMention = DateTime.UtcNow;
|
||||
}
|
||||
finally
|
||||
{
|
||||
TheDoor.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -176,6 +176,7 @@ namespace CompatBot
|
||||
client.MessageCreated += LogParsingHandler.OnMessageCreated;
|
||||
client.MessageCreated += LogAsTextMonitor.OnMessageCreated;
|
||||
client.MessageCreated += DiscordInviteFilter.OnMessageCreated;
|
||||
client.MessageCreated += PostLogHelpHandler.OnMessageCreated;
|
||||
client.MessageCreated += BotShutupHandler.OnMessageCreated;
|
||||
client.MessageCreated += AppveyorLinksHandler.OnMessageCreated;
|
||||
client.MessageCreated += GithubLinksHandler.OnMessageCreated;
|
||||
|
Loading…
Reference in New Issue
Block a user