-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUserActivityRecording.cs
67 lines (53 loc) · 1.58 KB
/
UserActivityRecording.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.IO;
using MikuBot.Commands;
using MikuBot.ExtraPlugins.Helpers;
using MikuBot.Modules;
namespace MikuBot.ExtraPlugins
{
public class UserActivityRecording : GenericModuleBase
{
private const string activityFile = "UserActivity.xml";
private readonly TimeSpan saveFrequency = TimeSpan.FromMinutes(5);
private DateTime lastSaved = DateTime.MinValue;
private UserActivityMonitor userActivityMonitor;
private void Save()
{
using (var f = File.Create(activityFile))
userActivityMonitor.Save(f);
lastSaved = DateTime.Now;
}
public override string HelpText
{
get { return "Records information on when a specific nickname was last active."; }
}
public override void HandleCommand(IrcCommand command, IBotContext bot)
{
if (command.Sender == null || !command.ChannelOrSenderNick.IsChannel)
return;
userActivityMonitor.Update(command.ChannelOrSenderNick, command.Sender.Nick, command.Command);
if (lastSaved + saveFrequency < DateTime.Now)
Save();
}
public override void OnDisconnected(IBotContext bot)
{
Save();
}
public override void OnLoaded(IBotContext bot, IModuleFile moduleFile)
{
ParamIs.NotNull(() => moduleFile);
var extraPluginsModuleFile = (ExtraPluginsModuleFile)moduleFile;
userActivityMonitor = extraPluginsModuleFile.UserActivityMonitor;
if (File.Exists(activityFile))
{
using (var f = File.OpenRead(activityFile))
userActivityMonitor.Restore(f);
lastSaved = DateTime.Now;
}
}
public override string Name
{
get { return "UserActivityRecording"; }
}
}
}