-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnctools.py
229 lines (203 loc) · 9.58 KB
/
nctools.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import sopel.module
import sopel.formatting
import time
import calendar
from threading import Timer
import urllib
import json
@sopel.module.commands('sm')
@sopel.module.example('!sm 45', '<username> cannot be healed for 45 minutes')
def notify_sm(bot, trigger):
"""Notifies once SM count (minutes) is over."""
try:
sm_count = int(trigger.group(2).rstrip(' '))
except:
bot.say('You need to specify minutes, eg !sm 10')
return
bot.say(trigger.nick + ' can\'t be healed for ' + str(sm_count) + ' minutes due to SM')
Timer(sm_count * 60, bot.say, [trigger.nick + ' can now be healed!']).start()
@sopel.module.commands('ping')
@sopel.module.example('!ping <message>', 'channeluser1 channeluser2 <message>')
def notify_ping(bot, trigger):
"""Pings everyone in the channel and tells them a message"""
if trigger.group(2) is None:
bot.say('Usage: !ping <message>')
return
if trigger.sender[0] == '#':
nicks_in_channel = ''
for nick in bot.privileges[trigger.sender]:
nicks_in_channel += nick + ' '
bot.say(nicks_in_channel)
bot.say(sopel.formatting.color(trigger.group(2), fg='YELLOW', bg='BLACK'))
@sopel.module.commands('nctime')
@sopel.module.example('!nctime', 'It is DAY and 15:12 in the Nexus')
def notify_time(bot, trigger):
"""Spits out gametime and whether or not it is day or night."""
hour = int(time.strftime('%H', time.gmtime()))
if hour % 2 == 0:
bot.say('It is ' + sopel.formatting.color('NIGHT', fg='BLACK', bg='GREY') + ' and ' + time.strftime('%H:%M', time.gmtime()) + ' in the Nexus')
else:
bot.say('It is ' + sopel.formatting.color('DAY', fg='BLACK', bg='YELLOW') + ' and ' + time.strftime('%H:%M', time.gmtime()) + ' in the Nexus')
@sopel.module.commands('char')
@sopel.module.example('!char Ygritte', 'NAME: Ygritte - LVL: 19 - CLASS: Sorcerer - STATUS: alive - FACTION: Oblivion Squadron http://www.nexusclash.com/modules.php?name=Game&op=character&id=8104')
def get_char(bot, trigger):
""" Looks up NC character, if found, returns summary and link """
if trigger.group(2) == None:
bot.say('Usage: !char <alt name>')
return
get_char_url = 'http://www.nexusclash.com/modules.php?name=Character&charname=' + trigger.group(2).rstrip(' ').replace(' ', '%20') + '&format=json'
response = urllib.urlopen(get_char_url)
data = json.loads(response.read())
if not data['result']['character']['name']['name'] == '':
char_lvl = str(data['result']['character']['level'])
char_name = data['result']['character']['name']['name']
char_class = data['result']['character']['classes'][-1]
char_id = str(data['result']['character']['id'])
if data['result']['character']['status']['alive'] == True:
char_status = 'alive'
else:
char_status = 'dead'
char_string = 'NAME: ' + char_name + ' - LVL: ' + char_lvl + ' - CLASS: ' + char_class + ' - STATUS: ' + char_status
if data['result']['character']['faction']['id'] != 0:
char_string += (' - FACTION: ' + data['result']['character']['faction']['name'])
char_string += ' http://www.nexusclash.com/modules.php?name=Game&op=character&id=' + char_id
bot.say(char_string)
else:
bot.say('Not found. Are you sure the name is correct?')
@sopel.module.commands('setraid')
@sopel.module.example('!setraid 20 01 16 02 30', 'Raid time set to 20 Jan 02:30 which is in 14 hours and 13 minutes')
def raid_set(bot, trigger):
"""Sets the raid time in DD MM YY HH MM format."""
try:
rawnewraidtime = trigger.group(2).rstrip(' ')
newraidtime = time.strptime(rawnewraidtime, '%d %m %y %H %M')
except:
bot.say('Usage: !setraid DD MM YY HH MM')
return
timediffinhours = (calendar.timegm(newraidtime) - calendar.timegm(time.gmtime())) / 60 / 60
remaindermins = ((calendar.timegm(newraidtime) - calendar.timegm(time.gmtime())) / 60) % 60
if (calendar.timegm(newraidtime) - calendar.timegm(time.gmtime())) < 0:
bot.say('You can\'t raid in the past!')
return
bot.db.set_channel_value(trigger.sender, 'raidtime', calendar.timegm(newraidtime))
bot.say(
'Raid time set to '
+ time.strftime('%d %b %H:%M', newraidtime)
+ ' which is in '
+ str(timediffinhours)
+ ' hours and '
+ str(remaindermins)
+ ' minutes'
)
@sopel.module.commands('setteamraid')
@sopel.module.example('!setteamraid 20 01 16 02 30 wolf', 'Raid time for team "wolf" set to 20 Jan 02:30 which is in 14 hours and 13 minutes')
def raid_setteam(bot, trigger):
"""Sets the raid time in <team> DD MM YY HH MM format."""
raidteams = bot.db.get_channel_value(trigger.sender, 'raidteams')
if not raidteams:
bot.say('No teams registered. Use !raidteam command to register a team first. ')
return
raidteam = trigger.group(2).split(' ')[0]
if raidteam not in raidteams.keys():
bot.say('That team does not exit. Usage: !setteamraid team DD MM YY HH MM')
return
try:
rawnewraidtime = trigger.group(2).rstrip(' ')[len(raidteam) + 1:]
newraidtime = time.strptime(rawnewraidtime, '%d %m %y %H %M')
except:
bot.say('Usage: !setteamraid team DD MM YY HH MM')
return
timediffinhours = (calendar.timegm(newraidtime) - calendar.timegm(time.gmtime())) / 60 / 60
remaindermins = ((calendar.timegm(newraidtime) - calendar.timegm(time.gmtime())) / 60) % 60
if (calendar.timegm(newraidtime) - calendar.timegm(time.gmtime())) < 0:
bot.say('You can\'t raid in the past!')
return
raidteams[raidteam] = calendar.timegm(newraidtime)
bot.db.set_channel_value(trigger.sender, 'raidteams', raidteams)
bot.say(
'Raid time for team '
+ raidteam
+ ' set to '
+ time.strftime('%d %b %H:%M', newraidtime)
+ ' which is in '
+ str(timediffinhours)
+ ' hours and '
+ str(remaindermins)
+ ' minutes'
)
@sopel.module.commands('whenraid')
@sopel.module.example('!whenraid', 'Next raid is at 20 Jan 02:30 which is in 12 hours and 31 minutes')
def raid_when(bot, trigger):
"""Returns the time raid was set using !setraid"""
raidteams = bot.db.get_channel_value(trigger.sender, 'raidteams')
if not raidteams:
raidteams = {}
raidtimeseconds = bot.db.get_channel_value(trigger.sender, 'raidtime')
if raidtimeseconds != None:
raidtime = time.gmtime(raidtimeseconds)
timediffinhours = (raidtimeseconds - calendar.timegm(time.gmtime())) / 60 / 60
remaindermins = ((raidtimeseconds - calendar.timegm(time.gmtime())) / 60) % 60
bot.say(
'Next primary raid is at '
+ time.strftime('%d %b %H:%M', raidtime)
+ ' which is in '
+ str(timediffinhours)
+ ' hours and '
+ str(remaindermins)
+ ' minutes'
)
for team in raidteams.keys():
raidtimeseconds = raidteams[team]
if raidtimeseconds != 0:
if raidtimeseconds - calendar.timegm(time.gmtime()) < 0:
continue
raidtime = time.gmtime(raidtimeseconds)
timediffinhours = (raidtimeseconds - calendar.timegm(time.gmtime())) / 60 / 60
remaindermins = ((raidtimeseconds - calendar.timegm(time.gmtime())) / 60) % 60
bot.say(
'Next team \''
+ team
+ '\' raid is at '
+ time.strftime('%d %b %H:%M', raidtime)
+ ' which is in '
+ str(timediffinhours)
+ ' hours and '
+ str(remaindermins)
+ ' minutes'
)
@sopel.module.commands('raidteam')
@sopel.module.example('!raidteam wolfpack', )
def raid_team(bot, trigger):
"""Creates a raid team in the channel"""
if trigger.group(2) == None:
bot.say('Usage: !raidteam <team name>')
return
raidteams = bot.db.get_channel_value(trigger.sender, 'raidteams')
if not raidteams:
raidteams = {}
raidteams[trigger.group(2).rstrip(' ')] = 0
bot.db.set_channel_value(trigger.sender, 'raidteams', raidteams)
@sopel.module.thread(False)
@sopel.module.rule('(.*)')
@sopel.module.priority('low')
def character_lookup_auto(bot, trigger):
""" Checks for NC character link, if found, returns summary """
possible_url_array = trigger.rstrip(' ').split('=')
if len(possible_url_array) < 3:
return
if possible_url_array[-2] == 'character&id':
get_char_url = 'http://www.nexusclash.com/modules.php?name=Character&id=' + possible_url_array[-1] + '&format=json'
response = urllib.urlopen(get_char_url)
data = json.loads(response.read())
if not data['result']['character']['name']['name'] == '':
char_lvl = str(data['result']['character']['level'])
char_name = data['result']['character']['name']['name']
char_class = data['result']['character']['classes'][-1]
if data['result']['character']['status']['alive'] == True:
char_status = 'alive'
else:
char_status = 'dead'
char_string = 'NAME: ' + char_name + ' - LVL: ' + char_lvl + ' - CLASS: ' + char_class + ' - STATUS: ' + char_status
if data['result']['character']['faction']['id'] != 0:
char_string += (' - FACTION: ' + data['result']['character']['faction']['name'])
bot.say(char_string)