Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion DiscordBot/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ulong, DateTime> _xpCooldown;
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Loading