-
Notifications
You must be signed in to change notification settings - Fork 4
/
Globals.cs
121 lines (101 loc) · 3.41 KB
/
Globals.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Collections.Generic;
using Decal.Adapter;
using Decal.Adapter.Wrappers;
namespace TownCrier
{
public static class Globals
{
// General globals
public static string PluginName { get; set; }
public static PluginHost Host { get; set; }
public static CoreManager Core { get; set; }
public static bool IsLoggedIn { get; set; } = false;
public static string Server { get; set; }
public static string Name { get; set; }
public static string PluginDirectory { get; set; }
public static string MessagesPath { get; set; }
public static string ErrorsPath { get; set; }
// App state
public static string CurrentProfile { get; set; } // null means "[By char]"
public static List<EventTrigger> EventTriggers { get; set; }
public static List<TimedTrigger> TimedTriggers { get; set; }
public static List<ChatTrigger> ChatTriggers { get; set; }
public static List<Webhook> Webhooks { get; set; }
public static List<ChatPattern> ChatPatterns { get; set; }
// Rate limiting stuff
public static DateTime RateLimitLastNotice { get; set; }
public static TimeSpan RateLimitNoticeWindowSpan { get; set; }
public static void Init(string pluginName, PluginHost host, CoreManager core, string server, string name)
{
// General globals
PluginName = pluginName;
Host = host;
Core = core;
IsLoggedIn = true;
Server = server;
Name = name;
// Set up PluginDirectory
SetPluginDirectory();
// App state
CurrentProfile = null;
EventTriggers = new List<EventTrigger>();
TimedTriggers = new List<TimedTrigger>();
ChatTriggers = new List<ChatTrigger>();
Webhooks = new List<Webhook>();
// Rate limiting
RateLimitNoticeWindowSpan = new TimeSpan(0, 1, 0);
}
public static void Destroy()
{
DisposeAllTimers();
if (ChatTriggers != null)
{
ChatTriggers.Clear();
}
if (EventTriggers != null)
{
EventTriggers.Clear();
}
if (TimedTriggers != null)
{
TimedTriggers.Clear();
}
if (Webhooks != null)
{
Webhooks.Clear();
}
if (ChatPatterns != null)
{
ChatPatterns.Clear();
}
}
public static void SetPluginDirectory()
{
try
{
PluginDirectory = string.Format(@"{0}\{1}\{2}",
Environment.GetFolderPath(Environment.SpecialFolder.Personal),
"Decal Plugins",
PluginName);
}
catch (Exception ex)
{
Utilities.LogError(ex);
}
}
public static void DisposeAllTimers()
{
if (TimedTriggers == null)
{
return;
}
foreach (TimedTrigger timer in TimedTriggers)
{
Utilities.LogMessage("Disposing of " + timer.ToString());
timer.Dispose();
}
TimedTriggers.Clear();
}
}
}