-
Notifications
You must be signed in to change notification settings - Fork 1
/
ModerationFunctions.cs
161 lines (154 loc) · 6.09 KB
/
ModerationFunctions.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using Discord;
using System.Collections.Generic;
namespace Discord_Bot
{
class ModerationFunctions
{
public static bool warnUser(IUser user, string reason, bool sendReason)
{
try
{
var userData = Program.instance.userDatabase.GetUserData(user.Id).Result;
if (userData != null)
{
userData.WarnData.WarnCount += 1;
if (userData.WarnData.WarnCount >= 3)
{
userData.WarnData.WarnCount = 0;
userData.WarnData.WarnEnds.Clear();
banUser(user, 0, "Превышено максимально количество предупреждений за нарушения!", true);
}
else
{
userData.WarnData.WarnEnds.Add(new handlers.WarnDataTimes(DateTime.Now));
if (sendReason && reason != null)
{
Program.instance.edenor.GetUser(user.Id).SendMessageAsync("Вы получили предупреждение по причине: " + reason);
}
}
Program.instance.userDatabase.ModifyUserData(user.Id, userData);
return true;
}
else
{
return false;
}
}
catch (Exception e)
{
Logger.logError("Failed to warn user " + e.Message);
return false;
}
}
public static bool giveRole(IUser user, long roleId)
{
try
{
((SocketGuildUser)user).AddRoleAsync((ulong)roleId);
return true;
}
catch (Exception e)
{
Logger.logError("Failed to give role to user " + e.Message);
return false;
}
}
public static bool removeRole(IUser user, long roleId)
{
try
{
((SocketGuildUser)user).RemoveRoleAsync((ulong)roleId);
return true;
}
catch (Exception e)
{
Logger.logError("Failed to remove role from user " + e.Message);
return false;
}
}
public static bool unTimeOutUser(IUser user, string reason)
{
try
{
((SocketGuildUser)user).RemoveTimeOutAsync(new RequestOptions { AuditLogReason = reason });
return true;
}
catch (Exception e)
{
Logger.logError("Failed to unTimeout user " + e.Message);
return false;
}
}
public static bool unBanUser(IUser user, string reason)
{
try
{
Program.instance.edenor.RemoveBanAsync(user, new RequestOptions { AuditLogReason = reason });
return true;
}
catch (Exception e)
{
Logger.logError("Failed to unban user " + e.Message);
return false;
}
}
public static bool banUser(IUser iuser, int days, string reason, bool sendReason = true)
{
try
{
if (Program.instance.edenor.GetUser(iuser.Id).SendMessageAsync($"Вы были забанены на сервере {Program.instance.edenor.Name}" +
$"{(sendReason ? $" по причине {reason}" : "")}!").Result == null)
Logger.logError("Не удалось отправить причину бана пользователю!");
Program.instance.edenor.AddBanAsync(iuser, days, reason, options: new RequestOptions { AuditLogReason = reason });
return true;
}
catch(Exception e)
{
Logger.logError("Failed to ban user " + e.Message);
return false;
}
}
public static bool timeOutUser(IUser iuser, TimeSpan? time, string reason, bool sendReason = true)
{
try
{
var user = iuser as SocketGuildUser;
if (time == null) time = TimeSpan.FromHours(1);
user.SendMessageAsync($"Вы были замучены на сервере {Program.instance.edenor.Name}{(sendReason ? $" по причине {reason}" : "")}!");
user.SetTimeOutAsync((TimeSpan)time, new RequestOptions { AuditLogReason = reason });
return true;
}
catch (Exception e)
{
Logger.logError("Failed to timeout user " + e.Message);
return false;
}
}
public static bool kickUser(IUser iuser, string reason, bool sendReason = true)
{
try
{
var user = iuser as SocketGuildUser;
if (user.SendMessageAsync($"Вы были кикнуты с сервера {Program.instance.edenor.Name}{(sendReason ? $" по причине {reason}" : "")}!").Result == null)
Logger.logError("Не удалось отправить причину кика пользователю!");
user.KickAsync(reason, options: new RequestOptions { AuditLogReason = reason });
return true;
}
catch (Exception e)
{
Logger.logError("Failed to kick user " + e.Message);
return false;
}
}
public static int getMaxUserRolePosition(ulong userId)
{
if (userId == 324794944042565643) return 2147483647;
if (Program.instance.edenor.GetUser(userId) == null) return 0;
else
{
SocketGuildUser user = Program.instance.edenor.GetUser(userId);
return user.Roles.OrderByDescending(x => x.Position).FirstOrDefault().Position;
}
}
}
}