/
commander.py
executable file
·184 lines (159 loc) · 5.16 KB
/
commander.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
177
178
179
180
181
182
183
184
#!/usr/bin/env python
#coding:utf-8
__author__ = 'eth2net [at] gmail.com'
__email__ = 'eth2net [at] gmail.com'
__date__ = '2013/01/25'
from db import get_collection
# Get from unified/src/com/redhat/gss/irc/irc_classes.py author: smendenh
BOLD = "\x02"
COLOR = "\x03"
CLEAR = "\x0F"
ITALIC = "\x10" # I don't think this actually works...
UNDERLINE = "\x1F"
WHITE = COLOR + "00"
BLACK = COLOR + "01"
BLUE = COLOR + "02"
GREEN = COLOR + "03"
RED = COLOR + "04"
BROWN = COLOR + "05"
PURPLE = COLOR + "06"
ORANGE = COLOR + "07"
YELLOW = COLOR + "08"
LT_GREEN = COLOR + "09"
TEAL = COLOR + "10"
CYAN = COLOR + "11"
LT_BLUE = COLOR + "12"
PINK = COLOR + "13"
GREY = COLOR + "14"
LT_GREY = COLOR + "15"
def help(bot, channel, user, args):
help_str = 'command format would be "^command <args>", command list: take, mute, unmute, report'
bot.msg(channel, help_str)
def take(bot, channel, user, cid):
p = get_collection('cases')
cid = cid.split()[0]
try:
int(cid)
except:
bot.msg(channel, '%s: case id incorrect' % user)
return False
case = p.find_one({'_id': cid})
if case is None:
bot.msg(channel, '%s: case id incorrect' % user)
return False
case['owner'] = user
case['mute'] = False
case['has_owner'] = True
if not case['nno']:
case['nno'] = False
p.update({'_id': cid}, case)
bot.msg(channel, 'gss_china: %s take case %s %s' % (user, case['_id'], case['subject']))
def mute(bot, channel, user, cid):
p = get_collection('cases')
case = p.find_one({'_id': cid})
if case:
case['mute'] = True
p.update({'_id': cid}, case)
if channel == bot.nick:
bot.reply(user, 'mute case: %s' % cid)
else:
bot.msg(channel, '%s, mute case: %s' % (user, cid))
else:
if channel == bot.nick:
bot.reply(user, 'I can\'t find the case %s' % cid)
else:
bot.msg(channel, '%s, I can\'t find the case: %s' % (user, cid))
def unmute(bot, channel, user, cid):
p = get_collection('cases')
case = p.find_one({'_id': cid})
if case:
case['mute'] = False
p.update({'_id': cid}, case)
if channel == bot.nick:
bot.reply(user, 'mute case: %s' % cid)
else:
bot.msg(channel, '%s, mute case: %s' % (user, cid))
else:
if channel == bot.nick:
bot.reply(user, 'I can\'t find the case %s' % cid)
else:
bot.msg(channel, '%s, I can\'t find the case: %s' % (user, cid))
def report(bot, channel, user, args):
p = get_collection('cases')
query_str = {
'$or': [
{'has_owner': False},
{'$and': [
{'nno': True},
{'mute': False}
]},
{'$and': [
{'status': 'WoRH'},
{'mute': False},
{'has_owner': False},
]},
]
}
cases = p.find(query_str)
for case in cases:
if case['region'] == 'HK':
msg_prefix = 'HK_Case'
elif case['region'] == 'TW':
msg_prefix = 'TW_Case'
elif case['region'] == 'KR':
msg_prefix = 'KR_Case'
elif case['region'] == 'CN':
msg_prefix = 'CN_Case'
else:
msg_prefix = 'Global_Case'
if case['severity'] == '1':
sev_str = BOLD + RED + 'S1' + CLEAR
elif case['severity'] == '2':
sev_str = BOLD + ORANGE + 'S2' + CLEAR
else:
sev_str = case['severity']
if case['sbt'] != '-':
if 0 <= int(case['sbt'].replace(',', '')) < 60:
sbt_str = BOLD + ORANGE + case['sbt'] + CLEAR
elif int(case['sbt'].replace(',', '')) < 0:
sbt_str = BOLD + ORANGE + case['sbt'] + CLEAR
else:
sbt_str = GREEN + case['sbt'] + CLEAR
else:
sbt_str = case['sbt']
msg_str = "%s: [%s%s%s] [%s] %s%s%s%s [%s %s] %s NNO:%s %s" % (
msg_prefix,
BOLD, case['_id'], CLEAR,
case['account'],
BOLD, BLUE, case['subject'], CLEAR,
sbt_str,
sev_str,
case['status'],
case['nno'],
case['url'],
)
bot.msg(channel, user + ' ' + msg_str)
def dhex(bot, channel, user, number):
try:
int(number)
except:
bot.msg(channel, user + ' you input an incorrect number')
bot.msg(channel, user + ' ' + hex(int(number)))
def dbin(bot, channel, user, number):
try:
int(number)
except:
bot.msg(channel, user + ' you input an incorrect number')
bot.msg(channel, user + ' ' + bin(int(number)))
def hexd(bot, channel, user, number):
if number.startswith('0x'):
bot.msg(channel, user + ' ' + str(int(number, 16)))
else:
bot.msg(channel, user + ' you input an incorrect number')
def bind(bot, channel, user, number):
if number.startswith('0b'):
bot.msg(channel, user + ' ' + str(int(number, 2)))
else:
bot.msg(channel, user + ' you input an incorrect number')
if __name__ == '__main__':
pass