-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCommand.cs
93 lines (76 loc) · 2.09 KB
/
Command.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
namespace WingTechBot;
using System;
using System.Linq;
using Discord;
using Discord.WebSocket;
public abstract class Command
{
protected SocketMessage message;
protected string[] arguments;
protected ulong[] userRoles;
protected IUser requested;
protected IMessage replied;
public void Init(SocketMessage message, string[] arguments)
{
this.message = message;
this.arguments = arguments;
if (message.Channel is SocketGuildChannel)
{
userRoles = ((IGuild)(message.Channel as SocketGuildChannel).Guild).GetUserAsync(message.Author.Id).Result.RoleIds.ToArray();
}
if (GetRequested)
{
requested = Program.GetUserFromMention(message, arguments);
if (requested is null)
{
throw new ArgumentException($"Command {Name} requires a user to be mentioned.");
}
}
if (GetReply)
{
try
{
replied = message.Channel.GetMessageAsync(message.Reference.MessageId.Value).Result;
}
catch { }
if (replied is null)
{
throw new ArgumentException($"Command {Name} must include a reply to another message");
}
}
if (RequiredRoles is not null)
{
if (message.Channel is SocketGuildChannel)
{
if (message.Author.Id != Program.Config.OwnerID && !RequiredRoles.Any(x => userRoles.Contains(x)))
{
throw new($"You do not have sufficient rank to call command {Name}.");
}
}
else
{
throw new($"Command {Name} cannot be called in DMs.");
}
}
if (OwnerOnly && message.Author.Id != Program.Config.OwnerID)
{
throw new($"Only {Program.GetUser(Program.Config.OwnerID).Mention} can call command {Name}.");
}
}
public abstract void Execute();
public abstract string LogString { get; }
public virtual ulong[] RequiredRoles { get; } = null;
public virtual bool GetRequested { get; } = false;
public virtual bool GetReply { get; } = false;
public virtual bool Audit { get; } = false;
public virtual bool OwnerOnly { get; } = false;
public string Name
{
get
{
var type = GetType();
return type.Name[..(type.Name.Length - "COMMAND".Length)];
}
}
public virtual string[] Aliases => new[] { Name.ToLower() };
}