forked from NotEnoughMods/NotEnoughModPolling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotEnoughMods_Queue.py
176 lines (163 loc) · 5.87 KB
/
NotEnoughMods_Queue.py
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
ID = "queue"
permission = 0
class NEM_Queue():
updatequeue = []
NEM = NEM_Queue()
def execute(self, name, params, channel, userdata, rank):
try:
if len(params) > 0:
if rankTranslate[rank] >= commands[params[0]]["rank"]:
command = commands[params[0]]["function"]
command(self, name, params, channel, userdata, rank)
else:
self.sendNotice(name, "You do not have permissions for this command!")
else:
self.sendChatMessage(self.send, channel, "{} item(s) in the queue.".format(len(NEM.updatequeue)))
except KeyError as e:
self.sendChatMessage(self.send, channel, str(e))
self.sendChatMessage(self.send, channel, "invalid command!")
self.sendChatMessage(self.send, channel, "see {}{} help for a list of commands".format(self.cmdprefix, ID))
def command_help(self, name, params, channel, userdata, rank):
actualRank = rankTranslate[rank]
paramCount = len(params)
if paramCount > 1:
# ok, info on a command, let's go!
if params[1] in commands:
commandInfo = commands[params[1]]
if actualRank < commandInfo["rank"]:
self.sendNotice(name, "You do not have permission for this command.")
return
if paramCount > 2:
param = " ".join(params[2:])
# We want info on an argument
argInfo = {}
for arg in commandInfo["args"]:
if param == arg["name"]:
argInfo = arg
break
self.sendNotice(name, argInfo["description"])
else: # just the command
# Lets compile the argStuff
argStuff = ""
argCount = len(commandInfo["args"])
if argCount > 0:
for arg in commandInfo["args"]:
if arg["required"]:
argStuff = argStuff + " <" + arg["name"] + ">"
else:
argStuff = argStuff + " [" + arg["name"] + "]"
# Send to IRC
self.sendNotice(name, commandInfo["help"])
self.sendNotice(name, "Use case: " + self.cmdprefix + ID + " " + params[1] + argStuff)
else:
self.sendNotice(name, "That isn't a command...")
return
else:
# List the commands
#0, 1, 2, 3
commandRanks = [[], [], [], []]
for command, info in commands.iteritems():
commandRanks[info["rank"]].append(command)
self.sendNotice(name, "Available commands:")
for i in range(0, actualRank):
if len(commandRanks[i]) > 0:
self.sendNotice(name, nameTranslate[i] + ": " + ", ".join(commandRanks[i]))
def command_show(self, name, params, channel, userdata, rank):
i = 0
if len(NEM.updatequeue) == 0:
self.sendChatMessage(self.send, channel, "There are no items currently in the queue.")
return
for item in NEM.updatequeue:
self.sendChatMessage(self.send, name, "{}: {}".format(i, item))
i += 1
def command_add(self, name, params, channel, userdata, rank):
NEM.updatequeue.append(" ".join(params[1:]))
self.sendChatMessage(self.send, channel, "Success!")
def command_remove(self, name, params, channel, userdata, rank):
if params[1].isdigit():
del NEM.updatequeue[int(params[1])]
self.sendChatMessage(self.send, channel, "Success!")
else:
self.sendChatMessage(self.send, channel, "'{}' is not a number.".format(params[1]))
def command_execute(self, name, params, channel, userdata, rank):
if params[1].isdigit():
index = int(params[1])
else:
self.sendChatMessage(self.send, channel, "'{}' is not a number.".format(params[2]))
return
if len(NEM.updatequeue) >= index and rank > 0:
self.sendChatMessage(self.send, channel, NEM.updatequeue[index])
del NEM.updatequeue[index]
self.sendChatMessage(self.send, channel, "Success!")
rankTranslate = {
"": 0,
"+": 1,
"@": 2,
"@@": 3
}
nameTranslate = [
"Guest",
"Voice",
"Operator",
"Bot Admin"
]
commands = {
"show": {
"function": command_show,
"rank": 0,
"help": "This will query you with the contents of the queue.",
"args": []
},
"add": {
"function": command_add,
"rank": 0,
"help": "This will add a new item to the queue.",
"args": [
{
"name": "modinfo",
"description": "the command to relay to ModBot if approved.",
"required": True
}
]
},
"remove": {
"function": command_remove,
"rank": 1,
"help": "This will remove an item from the queue. Usage: '=nemp queue del [index]'.",
"args": [
{
"name": "index",
"description": "the number attached to the item you wish to remove",
"required": True
}
]
},
"execute": {
"function": command_execute,
"rank": 1,
"help": "Executes the given index for ModBot to do its work",
"args": [
{
"name": "index",
"description": "the number attached to the item you wish to relay to ModBot",
"required": True
}
]
},
"help": {
"function": command_help,
"rank": 0,
"help": "Shows this info..?",
"args": [
{
"name": "command",
"description": "The command you want info for",
"required": False
}, {
"name": "arg",
"description": "The argument you want info for",
"required": False
}
]
}
}