diff --git a/DiscordBot/Services/UserService.cs b/DiscordBot/Services/UserService.cs index 2d5ccea6..6fc7bbba 100644 --- a/DiscordBot/Services/UserService.cs +++ b/DiscordBot/Services/UserService.cs @@ -41,8 +41,13 @@ public class UserService private readonly int _thanksCooldownTime; private readonly int _thanksMinJoinTime; - private readonly string _thanksRegex; + + private DateTime _mikuMentioned; + private readonly TimeSpan _mikuCooldownTime; + private readonly string _mikuRegex; + private readonly string _mikuReply; + private readonly UpdateService _updateService; private readonly Dictionary _xpCooldown; @@ -106,6 +111,17 @@ Init thanks _thanksCooldownTime = userSettings.ThanksCooldown; _thanksMinJoinTime = userSettings.ThanksMinJoinTime; + /* + Init Miku + Gag feature has no external settings, hardcoded userid refers to Reenaki/Kiki. + */ + _mikuMentioned = DateTime.Now; + _mikuCooldownTime = new TimeSpan(0, 39, 0); // 39min + //_mikuCooldownTime = new TimeSpan(0, 0, 39); // test 39sec + _mikuRegex = @"(?i)\b(miku|hatsune|初音ミク|初音|ミク)\b"; + _mikuReply = ":three: :nine: Oi, mite, mite, <@358915848515354626> -chan!"; + //_mikuReply = "Oi, mite, mite, <@427306565184389132> ! :three: :nine:"; // test + /* Init Code analysis */ @@ -140,6 +156,7 @@ Event subscriptions _client.MessageReceived += UpdateXp; _client.MessageReceived += Thanks; _client.MessageUpdated += ThanksEdited; + _client.MessageReceived += MikuCheck; _client.MessageReceived += CodeCheck; _client.MessageReceived += ScoldForAtEveryoneUsage; _client.MessageReceived += AutoCreateThread; @@ -503,6 +520,30 @@ await messageParam.Channel.SendMessageAsync( } } + public async Task MikuCheck(SocketMessage messageParam) + { + //Get guild id + var channel = (SocketGuildChannel)messageParam.Channel; + var guildId = channel.Guild.Id; + + //Make sure its in the UDC server + if (guildId != _settings.GuildId) return; + + if (messageParam.Author.IsBot) + return; + + var now = DateTime.Now; + if ((DateTime.Now - _mikuMentioned) < _mikuCooldownTime) + return; + + var match = Regex.Match(messageParam.Content, _mikuRegex); + if (!match.Success) + return; + + _mikuMentioned = now; + await messageParam.Channel.SendMessageAsync(_mikuReply); + } + public async Task CodeCheck(SocketMessage messageParam) { // Don't correct a Bot, don't correct in off-topic