6b1b3f46 by Barry

Bug fix for parameters.

Added battle logic for pankration
1 parent 75359516
No preview for this file type
...@@ -28,7 +28,7 @@ import sqlite3 ...@@ -28,7 +28,7 @@ import sqlite3
28 from blackjack import Blackjack 28 from blackjack import Blackjack
29 import data 29 import data
30 30
31 VERSION = 2.2 31 VERSION = 2.3
32 32
33 quitting = False 33 quitting = False
34 34
...@@ -94,6 +94,13 @@ def log(message): ...@@ -94,6 +94,13 @@ def log(message):
94 except: 94 except:
95 pass 95 pass
96 96
97 def send_message(client, target, message):
98 if type(target) is not discord.channel.PrivateChannel:
99 if target.id == '121468616414724100':
100 return
101 elif datetime.datetime.now() < muted_until:
102 return
103 client.send_message(target, message)
97 104
98 def format_exception(e): 105 def format_exception(e):
99 exception_list = traceback.format_stack() 106 exception_list = traceback.format_stack()
...@@ -155,33 +162,7 @@ def search_google_images(query, animated=False): ...@@ -155,33 +162,7 @@ def search_google_images(query, animated=False):
155 return "boo you fail.." 162 return "boo you fail.."
156 163
157 164
158 ################# 165 def check_msg_queue(client):
159 # Client Events
160 #################
161 @client.event
162 def on_socket_raw_send(payload, binary=False):
163 check_msg_queue()
164
165
166 @client.event
167 def on_status(member):
168 for member in client.get_all_members():
169 try:
170 db_member = data.db_get_member(member.id)
171
172 if not db_member:
173 log("Creating new member: {}".format(member))
174 data.db_create_member(member)
175 else:
176 data.db_update_member(member, db_member)
177
178 check_msg_queue()
179 except Exception as e:
180 log("Exception: {}".format(format_exception(e)))
181 pass
182
183
184 def check_msg_queue():
185 messages = data.db_get_messages() 166 messages = data.db_get_messages()
186 if messages: 167 if messages:
187 for message in messages: 168 for message in messages:
...@@ -210,17 +191,17 @@ def do_roll(client, message_parts, message): ...@@ -210,17 +191,17 @@ def do_roll(client, message_parts, message):
210 count = int(dice_parts[0]) 191 count = int(dice_parts[0])
211 dice = int(dice_parts[1]) 192 dice = int(dice_parts[1])
212 if count > 100000000000000000: 193 if count > 100000000000000000:
213 client.send_message(message.channel, '{} stop fucking around with those stupid numbers...'.format(message.author.mention())) 194 send_message(client, message.channel, '{} stop fucking around with those stupid numbers...'.format(message.author.mention()))
214 return 195 return
215 196
216 if count > 100: 197 if count > 100:
217 client.send_message(message.channel, '{} 100 is the largest number of dice I will roll.'.format(message.author.mention())) 198 send_message(client, message.channel, '{} 100 is the largest number of dice I will roll.'.format(message.author.mention()))
218 return 199 return
219 roll_results = [] 200 roll_results = []
220 for i in range(count): 201 for i in range(count):
221 roll_results.append(random.randint(1, dice)) 202 roll_results.append(random.randint(1, dice))
222 out_string = '{} your roll {}d{}: {} = {}'.format(message.author.mention(), count, dice, '+'.join(str(r) for r in roll_results), sum(roll_results)) 203 out_string = '{} your roll {}d{}: {} = {}'.format(message.author.mention(), count, dice, '+'.join(str(r) for r in roll_results), sum(roll_results))
223 client.send_message(message.channel, out_string) 204 send_message(client, message.channel, out_string)
224 return 205 return
225 206
226 207
...@@ -240,14 +221,14 @@ def do_lastseen(client, message_parts, message): ...@@ -240,14 +221,14 @@ def do_lastseen(client, message_parts, message):
240 human(datetime.datetime.strptime(member['status_change_at'], '%Y/%m/%d %H:%M:%S')), 221 human(datetime.datetime.strptime(member['status_change_at'], '%Y/%m/%d %H:%M:%S')),
241 member['prev_status']) 222 member['prev_status'])
242 223
243 client.send_message(message.channel, 'Last Information on {}:\n{}'.format(byteify(username), out_string)) 224 send_message(client, message.channel, 'Last Information on {}:\n{}'.format(byteify(username), out_string))
244 else: 225 else:
245 client.send_message(message.channel, 'I don\'t have any data on {} yet {}'.format(byteify(username), message.author.mention())) 226 send_message(client, message.channel, 'I don\'t have any data on {} yet {}'.format(byteify(username), message.author.mention()))
246 return 227 return
247 228
248 229
249 def do_help(client, message_parts, message): 230 def do_help(client, message_parts, message):
250 client.send_message(message.channel, """{} Available Commands: 231 send_message(client, message.channel, """{} Available Commands:
251 You can ask compound or questions and I will choose. Example: HellsBot Rui is a Faggot or Rui is a faggot? 232 You can ask compound or questions and I will choose. Example: HellsBot Rui is a Faggot or Rui is a faggot?
252 233
253 User Info: 234 User Info:
...@@ -270,7 +251,7 @@ Minigames: ...@@ -270,7 +251,7 @@ Minigames:
270 !hit - Draw a card 251 !hit - Draw a card
271 !stand - Show the cards 252 !stand - Show the cards
272 """.format(message.author.mention())) 253 """.format(message.author.mention()))
273 client.send_message(message.channel, """ 254 send_message(client, message.channel, """
274 !balance - Lists your current credits and tickets 255 !balance - Lists your current credits and tickets
275 !buyticket - Purchases a raffle ticket for 100 credits 256 !buyticket - Purchases a raffle ticket for 100 credits
276 !raffle - Shows information about the current raffle 257 !raffle - Shows information about the current raffle
...@@ -294,33 +275,34 @@ Stuff: ...@@ -294,33 +275,34 @@ Stuff:
294 def do_shutup(client, message_parts, message): 275 def do_shutup(client, message_parts, message):
295 global muted_until 276 global muted_until
296 muted_until = datetime.datetime.now() + datetime.timedelta(minutes=5) 277 muted_until = datetime.datetime.now() + datetime.timedelta(minutes=5)
297 client.send_message(message.channel, 'All image / gif / youtube spam disabled for 5 minutes') 278 send_message(client, message.channel, 'All image / gif / youtube spam disabled for 5 minutes')
298 return 279 return
299 280
300 281
301 def do_youtube(client, message_parts, message): 282 def do_youtube(client, message_parts, message):
302 if datetime.datetime.now() < muted_until: 283 if datetime.datetime.now() < muted_until:
303 return 284 return
304 client.send_message(message.channel, search_youtube(' '.join(message_parts))) 285 send_message(client, message.channel, search_youtube(' '.join(message_parts)))
305 return 286 return
306 287
307 288
308 def do_image(client, message_parts, message): 289 def do_image(client, message_parts, message):
309 if datetime.datetime.now() < muted_until: 290 if datetime.datetime.now() < muted_until:
310 return 291 return
311 client.send_message(message.channel, search_google_images(' '.join(message_parts))) 292 send_message(client, message.channel, search_google_images(' '.join(message_parts)))
312 return 293 return
313 294
314 295
315 def do_gif(client, message_parts, message): 296 def do_gif(client, message_parts, message):
316 if datetime.datetime.now() < muted_until: 297 if datetime.datetime.now() < muted_until:
317 return 298 return
318 client.send_message(message.channel, search_google_images(' '.join(message_parts), True)) 299 send_message(client, message.channel, search_google_images(' '.join(message_parts), True))
319 return 300 return
320 301
321 302
322 def do_gameslist(client, message_parts, message): 303 def do_gameslist(client, message_parts, message):
323 limit = 20 304 limit = 20
305 log("parts: {} {}".format(message_parts,message))
324 if len(message_parts) > 0 and message_parts[0].isdigit(): 306 if len(message_parts) > 0 and message_parts[0].isdigit():
325 limit = int(message_parts[0]) 307 limit = int(message_parts[0])
326 games_list = data.db_get_games_list(limit) 308 games_list = data.db_get_games_list(limit)
...@@ -328,9 +310,9 @@ def do_gameslist(client, message_parts, message): ...@@ -328,9 +310,9 @@ def do_gameslist(client, message_parts, message):
328 out_string = '' 310 out_string = ''
329 for game in games_list: 311 for game in games_list:
330 out_string += ' {} - {}\n'.format(game[1], byteify(game[0])) 312 out_string += ' {} - {}\n'.format(game[1], byteify(game[0]))
331 client.send_message(message.channel, 'The games I have seen people playing are: ') 313 send_message(client, message.channel, 'The games I have seen people playing are: ')
332 while len(out_string) > 0: 314 while len(out_string) > 0:
333 client.send_message(message.channel, out_string[:1900]) 315 send_message(client, message.channel, out_string[:1900])
334 out_string = out_string[1900:] 316 out_string = out_string[1900:]
335 return 317 return
336 318
...@@ -345,11 +327,11 @@ def do_alias(client, message_parts, message): ...@@ -345,11 +327,11 @@ def do_alias(client, message_parts, message):
345 if member: 327 if member:
346 aliases = data.db_get_aliases(member['member_id']) 328 aliases = data.db_get_aliases(member['member_id'])
347 if aliases: 329 if aliases:
348 client.send_message(message.channel, '{} has the following aliases: {}'.format(byteify(username), byteify(', '.join(aliases)))) 330 send_message(client, message.channel, '{} has the following aliases: {}'.format(byteify(username), byteify(', '.join(aliases))))
349 else: 331 else:
350 client.send_message(message.channel, 'No known alises for {} yet {}'.format(byteify(username), message.author.mention())) 332 send_message(client, message.channel, 'No known alises for {} yet {}'.format(byteify(username), message.author.mention()))
351 else: 333 else:
352 client.send_message(message.channel, 'I don\'t know who you are speaking of {}!'.format(message.author.mention())) 334 send_message(client, message.channel, 'I don\'t know who you are speaking of {}!'.format(message.author.mention()))
353 return 335 return
354 336
355 337
...@@ -359,9 +341,9 @@ def do_addalias(client, message_parts, message): ...@@ -359,9 +341,9 @@ def do_addalias(client, message_parts, message):
359 member = data.db_get_member(username=username) 341 member = data.db_get_member(username=username)
360 if member: 342 if member:
361 data.db_add_aliases(member['member_id'], alias) 343 data.db_add_aliases(member['member_id'], alias)
362 client.send_message(message.channel, '{} has been added to your aliases'.format(byteify(alias))) 344 send_message(client, message.channel, '{} has been added to your aliases'.format(byteify(alias)))
363 else: 345 else:
364 client.send_message(message.channel, 'Something horrible happened and it is all your fault, try logging out / on again or play a game. (or fuck off i dunno i\'m just an error message. Who am I to tell you how to run your life...)') 346 send_message(client, message.channel, 'Something horrible happened and it is all your fault, try logging out / on again or play a game. (or fuck off i dunno i\'m just an error message. Who am I to tell you how to run your life...)')
365 return 347 return
366 348
367 349
...@@ -375,14 +357,14 @@ def do_games(client, message_parts, message): ...@@ -375,14 +357,14 @@ def do_games(client, message_parts, message):
375 games = ', '.join(games_list) 357 games = ', '.join(games_list)
376 games = games.replace("FINAL FANTASY XIV", "**FINAL FANTASY XIV**") 358 games = games.replace("FINAL FANTASY XIV", "**FINAL FANTASY XIV**")
377 log(byteify(games)) 359 log(byteify(games))
378 client.send_message(message.channel, 'I have seen {} playing: {}'.format(byteify(username), byteify(games))) 360 send_message(client, message.channel, 'I have seen {} playing: {}'.format(byteify(username), byteify(games)))
379 else: 361 else:
380 client.send_message(message.channel, 'I don\'t have any data on {} yet {}'.format(byteify(username), message.author.mention())) 362 send_message(client, message.channel, 'I don\'t have any data on {} yet {}'.format(byteify(username), message.author.mention()))
381 363
382 364
383 def do_reload(client, message_parts, message): 365 def do_reload(client, message_parts, message):
384 if message.author.id != '78767557628133376': 366 if message.author.id != '78767557628133376':
385 client.send_message(message.channel, "You shouldn't be calling this. You are clearly looking to piss Hellsbreath off.") 367 send_message(client, message.channel, "You shouldn't be calling this. You are clearly looking to piss Hellsbreath off.")
386 return 368 return
387 call(["service", "hellsbot", "restart"]) 369 call(["service", "hellsbot", "restart"])
388 370
...@@ -391,14 +373,14 @@ def do_whoplayed(client, message_parts, message): ...@@ -391,14 +373,14 @@ def do_whoplayed(client, message_parts, message):
391 game_name = ' '.join(message_parts) 373 game_name = ' '.join(message_parts)
392 member_list = data.db_get_whoplayed(game_name) 374 member_list = data.db_get_whoplayed(game_name)
393 if not member_list: 375 if not member_list:
394 client.send_message(message.channel, 'I don\'t have any data on {} yet {}'.format(byteify(game_name), message.author.mention())) 376 send_message(client, message.channel, 'I don\'t have any data on {} yet {}'.format(byteify(game_name), message.author.mention()))
395 else: 377 else:
396 out_string = '' 378 out_string = ''
397 for member in member_list: 379 for member in member_list:
398 out_string += ' {} - {}\n'.format(byteify(member[1]), byteify(member[0])) 380 out_string += ' {} - {}\n'.format(byteify(member[1]), byteify(member[0]))
399 client.send_message(message.channel, 'Below is a list of people who have played {} and the number of times they have launched the game:'.format(byteify(game_name),)) 381 send_message(client, message.channel, 'Below is a list of people who have played {} and the number of times they have launched the game:'.format(byteify(game_name),))
400 while len(out_string) > 0: 382 while len(out_string) > 0:
401 client.send_message(message.channel, out_string[:1900]) 383 send_message(client, message.channel, out_string[:1900])
402 out_string = out_string[1900:] 384 out_string = out_string[1900:]
403 return 385 return
404 386
...@@ -406,48 +388,48 @@ def do_whoplayed(client, message_parts, message): ...@@ -406,48 +388,48 @@ def do_whoplayed(client, message_parts, message):
406 def do_gimmecredits(client, message_parts, message): 388 def do_gimmecredits(client, message_parts, message):
407 member = data.db_get_member(message.author.id) 389 member = data.db_get_member(message.author.id)
408 if not member: 390 if not member:
409 client.send_message(message.author, "There was a problem looking up your information.") 391 send_message(client, message.author, "There was a problem looking up your information.")
410 else: 392 else:
411 credits = data.db_get_credit(member['member_id']) 393 credits = data.db_get_credit(member['member_id'])
412 if credits < 5: 394 if credits < 5:
413 amount = random.randint(5, 50) 395 amount = random.randint(5, 50)
414 data.db_update_credit(member['member_id'], amount) 396 data.db_update_credit(member['member_id'], amount)
415 client.send_message(message.author, "You have been given {} credits.".format(amount,)) 397 send_message(client, message.author, "You have been given {} credits.".format(amount,))
416 else: 398 else:
417 client.send_message(message.author, "You already have credits. Stop begging.") 399 send_message(client, message.author, "You already have credits. Stop begging.")
418 return 400 return
419 401
420 402
421 def do_grantcredits(client, message_parts, message, channel=None): 403 def do_grantcredits(client, message_parts, message, channel=None):
422 if not channel and message.author.id != '78767557628133376': 404 if not channel and message.author.id != '78767557628133376':
423 client.send_message(message.channel, "You are not Hellsbreath. Use !gimmecredits to get a few extra if you run out.") 405 send_message(client, message.channel, "You are not Hellsbreath. Use !gimmecredits to get a few extra if you run out.")
424 return 406 return
425 members = data.db_get_all_members() 407 members = data.db_get_all_members()
426 if len(members) < 0: 408 if len(members) < 0:
427 client.send_message(message.channel, "There was a problem looking up your information.") 409 send_message(client, message.channel, "There was a problem looking up your information.")
428 else: 410 else:
429 for member in members: 411 for member in members:
430 credits = data.db_get_credit(member['member_id']) 412 credits = data.db_get_credit(member['member_id'])
431 if credits < 100: 413 if credits < 100:
432 data.db_update_credit(member['member_id'], 100) 414 data.db_update_credit(member['member_id'], 100)
433 if channel: 415 if channel:
434 client.send_message(channel, "{} has been given {} credits.".format(member['member_name'], 100)) 416 send_message(client, channel, "{} has been given {} credits.".format(member['member_name'], 100))
435 else: 417 else:
436 client.send_message(message.channel, "{} has been given {} credits.".format(member['member_name'], 100)) 418 send_message(client, message.channel, "{} has been given {} credits.".format(member['member_name'], 100))
437 return 419 return
438 420
439 421
440 def do_ticketrank(client, message_parts, message): 422 def do_ticketrank(client, message_parts, message):
441 members = data.db_get_all_members() 423 members = data.db_get_all_members()
442 if len(members) < 0: 424 if len(members) < 0:
443 client.send_message(message.channel, "There was a problem looking up your information.") 425 send_message(client, message.channel, "There was a problem looking up your information.")
444 else: 426 else:
445 ticket_count = 0 427 ticket_count = 0
446 for member in members: 428 for member in members:
447 if member['discord_id'] != '78767557628133376': 429 if member['discord_id'] != '78767557628133376':
448 ticket_count += member['tickets'] 430 ticket_count += member['tickets']
449 if ticket_count == 0: 431 if ticket_count == 0:
450 client.send_message(message.channel, "No Tickets have been sold for this raffle.") 432 send_message(client, message.channel, "No Tickets have been sold for this raffle.")
451 return 433 return
452 434
453 out_string = "" 435 out_string = ""
...@@ -456,24 +438,24 @@ def do_ticketrank(client, message_parts, message): ...@@ -456,24 +438,24 @@ def do_ticketrank(client, message_parts, message):
456 percent = (float(member['tickets']) / float(ticket_count)) * 100.0 438 percent = (float(member['tickets']) / float(ticket_count)) * 100.0
457 out_string += "{} - {}%\n".format(byteify(member['member_name']), int(percent)) 439 out_string += "{} - {}%\n".format(byteify(member['member_name']), int(percent))
458 440
459 client.send_message(message.channel, out_string) 441 send_message(client, message.channel, out_string)
460 return 442 return
461 443
462 444
463 def do_startraffle(client, message_parts, message): 445 def do_startraffle(client, message_parts, message):
464 if message.author.id != '78767557628133376': 446 if message.author.id != '78767557628133376':
465 client.send_message(message.channel, "You are not Hellsbreath. Go die in an especially hot fire.") 447 send_message(client, message.channel, "You are not Hellsbreath. Go die in an especially hot fire.")
466 return 448 return
467 members = data.db_get_all_members() 449 members = data.db_get_all_members()
468 if len(members) < 0: 450 if len(members) < 0:
469 client.send_message(message.channel, "There was a problem looking up your information.") 451 send_message(client, message.channel, "There was a problem looking up your information.")
470 else: 452 else:
471 ticket_count = 0 453 ticket_count = 0
472 for member in members: 454 for member in members:
473 if member['discord_id'] != '78767557628133376': 455 if member['discord_id'] != '78767557628133376':
474 ticket_count += member['tickets'] 456 ticket_count += member['tickets']
475 if ticket_count == 0: 457 if ticket_count == 0:
476 client.send_message(message.channel, "No Tickets have been sold for this raffle.") 458 send_message(client, message.channel, "No Tickets have been sold for this raffle.")
477 return 459 return
478 460
479 out_string = "The final standings are as follows: \n\n" 461 out_string = "The final standings are as follows: \n\n"
...@@ -502,24 +484,25 @@ def do_startraffle(client, message_parts, message): ...@@ -502,24 +484,25 @@ def do_startraffle(client, message_parts, message):
502 winner = random.choice(ticket_reel) 484 winner = random.choice(ticket_reel)
503 while winner in ticket_reel: 485 while winner in ticket_reel:
504 ticket_reel.remove(winner) 486 ticket_reel.remove(winner)
505 client.send_message(message.channel, "\n\n\n**The winner is....\n\n{}!**".format(byteify(winner))) 487 send_message(client, message.channel, "\n\n\n**The winner is....\n\n{}!**".format(byteify(winner)))
506 if len(ticket_reel) > 0: 488 if len(ticket_reel) > 0:
507 second = random.choice(ticket_reel) 489 second = random.choice(ticket_reel)
508 while second in ticket_reel: 490 while second in ticket_reel:
509 ticket_reel.remove(second) 491 ticket_reel.remove(second)
510 time.sleep(0.5) 492 time.sleep(0.5)
511 client.send_message(message.channel, "\n\n*2nd Place:* {}".format(byteify(second))) 493 send_message(client, message.channel, "\n\n*2nd Place:* {}".format(byteify(second)))
512 if len(ticket_reel) > 0: 494 if len(ticket_reel) > 0:
513 third = random.choice(ticket_reel) 495 third = random.choice(ticket_reel)
514 time.sleep(0.5) 496 time.sleep(0.5)
515 client.send_message(message.channel, "\n*3rd Place:* {}".format(byteify(third))) 497 send_message(client, message.channel, "\n*3rd Place:* {}".format(byteify(third)))
516 498
517 for member in client.get_all_members(): 499 for member in client.get_all_members():
518 log(member.id) 500 log(member.id)
519 if member.id == '78767557628133376': 501 if member.id == '78767557628133376':
520 priv_message = "1st: {} key: {}\n2nd: {} keys: {}\n3rd: {} keys: {}".format(byteify(winner), game_key, byteify(second), ' '.join(random_keys[0:2]), byteify(third), random_keys[3]) 502 priv_message = "1st: {} key: {}\n2nd: {} keys: {}\n3rd: {} keys: {}".format(byteify(winner), game_key, byteify(second), ' '.join(random_keys[0:2]), byteify(third), random_keys[3])
521 log(priv_message) 503 log(priv_message)
522 client.send_message(member, priv_message) 504 send_message(client, member, priv_message)
505 break
523 506
524 return 507 return
525 508
...@@ -532,7 +515,7 @@ def do_pastraffle(client, message_parts, message): ...@@ -532,7 +515,7 @@ def do_pastraffle(client, message_parts, message):
532 for key, value in raffles.iteritems(): 515 for key, value in raffles.iteritems():
533 if value['current'] == 0: 516 if value['current'] == 0:
534 out_str += "{} - {}\n".format(key, value['title']) 517 out_str += "{} - {}\n".format(key, value['title'])
535 client.send_message(message.channel, "Past Raffles:\n\n{}".format(out_str)) 518 send_message(client, message.channel, "Past Raffles:\n\n{}".format(out_str))
536 return 519 return
537 520
538 521
...@@ -550,7 +533,7 @@ def do_raffle(client, message_parts, message): ...@@ -550,7 +533,7 @@ def do_raffle(client, message_parts, message):
550 title = value['title'] 533 title = value['title']
551 description = value['description'] 534 description = value['description']
552 link = value['link'] 535 link = value['link']
553 client.send_message(message.channel, """Current Raffle Item: 536 send_message(client, message.channel, """Current Raffle Item:
554 537
555 **1st Place** 538 **1st Place**
556 539
...@@ -574,7 +557,7 @@ You will be contacted if you win. To win you must purchase tickets with the !buy ...@@ -574,7 +557,7 @@ You will be contacted if you win. To win you must purchase tickets with the !buy
574 You can get extra credits by playing !slots <amount> and !bet <amount> on BlackJack. 557 You can get extra credits by playing !slots <amount> and !bet <amount> on BlackJack.
575 558
576 **Disclaimer:** *If anything should go wrong you get no refund and there is no guarantee or warrantee on anything. 1 prize per person no matter how many tickets you have.* 559 **Disclaimer:** *If anything should go wrong you get no refund and there is no guarantee or warrantee on anything. 1 prize per person no matter how many tickets you have.*
577 """.format(title, description, link, date)) 560 """.format(title, byteify(description), link, date))
578 return 561 return
579 562
580 563
...@@ -584,32 +567,32 @@ def do_buyticket(client, message_parts, message): ...@@ -584,32 +567,32 @@ def do_buyticket(client, message_parts, message):
584 log("Member: {}".format(member,)) 567 log("Member: {}".format(member,))
585 if not member: 568 if not member:
586 log("there") 569 log("there")
587 client.send_message(message.author, "There was a problem looking up your information.") 570 send_message(client, message.author, "There was a problem looking up your information.")
588 else: 571 else:
589 log("here") 572 log("here")
590 log("Buying Ticket for: {}".format(byteify(member['member_name']))) 573 log("Buying Ticket for: {}".format(byteify(member['member_name'])))
591 result, response = data.db_buy_ticket(member['member_id'], 1) 574 result, response = data.db_buy_ticket(member['member_id'], 1)
592 log("Buy Result: {} - {}".format(result, response)) 575 log("Buy Result: {} - {}".format(result, response))
593 if not result: 576 if not result:
594 client.send_message(message.author, response) 577 send_message(client, message.author, response)
595 return 578 return
596 579
597 credits = data.db_get_credit(member['member_id']) 580 credits = data.db_get_credit(member['member_id'])
598 client.send_message(message.author, "Raffle ticket purchased. Tickets: {} Credits: {}".format(response, credits)) 581 send_message(client, message.author, "Raffle ticket purchased. Tickets: {} Credits: {}".format(response, credits))
599 return 582 return
600 583
601 584
602 def do_balance(client, message_parts, message): 585 def do_balance(client, message_parts, message):
603 member = data.db_get_member(message.author.id) 586 member = data.db_get_member(message.author.id)
604 if not member: 587 if not member:
605 client.send_message(message.author, "There was a problem looking up your information.") 588 send_message(client, message.author, "There was a problem looking up your information.")
606 else: 589 else:
607 client.send_message(message.author, "Credits: {}\nTickets: {}".format(member['credits'], member['tickets'])) 590 send_message(client, message.author, "Credits: {}\nTickets: {}".format(member['credits'], member['tickets']))
608 return 591 return
609 592
610 593
611 def do_slotsrules(client, message_parts, message): 594 def do_slotsrules(client, message_parts, message):
612 client.send_message(message.channel, """Paying Combinations: 595 send_message(client, message.channel, """Paying Combinations:
613 596
614 :moneybag:\t:moneybag:\t:moneybag:\t\t\t pays\t250 597 :moneybag:\t:moneybag:\t:moneybag:\t\t\t pays\t250
615 :bell:\t:bell:\t:bell:/:moneybag:\tpays\t20 598 :bell:\t:bell:\t:bell:/:moneybag:\tpays\t20
...@@ -632,20 +615,20 @@ To Play: !slots <bet>""") ...@@ -632,20 +615,20 @@ To Play: !slots <bet>""")
632 def do_slots(client, message_parts, message): 615 def do_slots(client, message_parts, message):
633 member = data.db_get_member(message.author.id) 616 member = data.db_get_member(message.author.id)
634 if not member: 617 if not member:
635 client.send_message(message.author, "There was a problem looking up your information.") 618 send_message(client, message.author, "There was a problem looking up your information.")
636 return 619 return
637 elif type(message.channel) is not discord.channel.PrivateChannel: 620 elif type(message.channel) is not discord.channel.PrivateChannel:
638 client.send_message(message.author, "You must make all bets / gaming via private message.") 621 send_message(client, message.author, "You must make all bets / gaming via private message.")
639 return 622 return
640 bet_amount = message.content[7:] 623 bet_amount = message.content[7:]
641 log("Member: {} Slots Bet: {}".format(member['member_name'], bet_amount)) 624 log("Member: {} Slots Bet: {}".format(member['member_name'], bet_amount))
642 625
643 if not bet_amount.isdigit() or int(bet_amount) > 10 or int(bet_amount) < 0: 626 if not bet_amount.isdigit() or int(bet_amount) > 10 or int(bet_amount) < 0:
644 client.send_message(message.author, "Please provide a bet amount up to 10 credits.") 627 send_message(client, message.author, "Please provide a bet amount up to 10 credits.")
645 return 628 return
646 result, error_message = data.db_update_credit(member['member_id'], -int(bet_amount)) 629 result, error_message = data.db_update_credit(member['member_id'], -int(bet_amount))
647 if not result: 630 if not result:
648 client.send_message(message.author, error_message) 631 send_message(client, message.author, error_message)
649 return 632 return
650 633
651 reel1 = [':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':cherries:', ':cherries:', ':cherries:', ':spades:', ':spades:', ':spades:', ':hearts:', ':hearts:', ':diamonds:', ':bell:', ':moneybag:'] 634 reel1 = [':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':black_square_button:', ':cherries:', ':cherries:', ':cherries:', ':spades:', ':spades:', ':spades:', ':hearts:', ':hearts:', ':diamonds:', ':bell:', ':moneybag:']
...@@ -689,22 +672,22 @@ def do_slots(client, message_parts, message): ...@@ -689,22 +672,22 @@ def do_slots(client, message_parts, message):
689 if winnings > 0: 672 if winnings > 0:
690 result, error_message = data.db_update_credit(member['member_id'], winnings) 673 result, error_message = data.db_update_credit(member['member_id'], winnings)
691 if not result: 674 if not result:
692 client.send_message(message.author, error_message) 675 send_message(client, message.author, error_message)
693 return 676 return
694 677
695 credits = data.db_get_credit(member['member_id']) 678 credits = data.db_get_credit(member['member_id'])
696 out_string += "\nCredits: {}".format(credits) 679 out_string += "\nCredits: {}".format(credits)
697 680
698 client.send_message(message.author, out_string) 681 send_message(client, message.author, out_string)
699 return 682 return
700 683
701 684
702 def do_bj_hit(client, message_parts, message): 685 def do_bj_hit(client, message_parts, message):
703 member = data.db_get_member(message.author.id) 686 member = data.db_get_member(message.author.id)
704 if not member: 687 if not member:
705 client.send_message(message.author, "There was a problem looking up your information.") 688 send_message(client, message.author, "There was a problem looking up your information.")
706 elif type(message.channel) is not discord.channel.PrivateChannel: 689 elif type(message.channel) is not discord.channel.PrivateChannel:
707 client.send_message(message.author, "You must make all bets / gaming via private message.") 690 send_message(client, message.author, "You must make all bets / gaming via private message.")
708 else: 691 else:
709 state = data.db_get_minigame_state(member['member_id'], 'blackjack') 692 state = data.db_get_minigame_state(member['member_id'], 'blackjack')
710 if state: 693 if state:
...@@ -724,25 +707,25 @@ def do_bj_hit(client, message_parts, message): ...@@ -724,25 +707,25 @@ def do_bj_hit(client, message_parts, message):
724 log("{} - {}".format(member['member_name'], response.format(win,))) 707 log("{} - {}".format(member['member_name'], response.format(win,)))
725 result, error_message = data.db_update_credit(member['member_id'], int(win)) 708 result, error_message = data.db_update_credit(member['member_id'], int(win))
726 if not result: 709 if not result:
727 client.send_message(message.author, error_message) 710 send_message(client, message.author, error_message)
728 return 711 return
729 712
730 credits = data.db_get_credit(member['member_id']) 713 credits = data.db_get_credit(member['member_id'])
731 out_string += "\nCredits: {}".format(credits) 714 out_string += "\nCredits: {}".format(credits)
732 715
733 client.send_message(message.author, out_string) 716 send_message(client, message.author, out_string)
734 717
735 else: 718 else:
736 client.send_message(message.author, "You must start a game with !bet before you can ask for a new card.") 719 send_message(client, message.author, "You must start a game with !bet before you can ask for a new card.")
737 return 720 return
738 721
739 722
740 def do_bj_stay(client, message_parts, message): 723 def do_bj_stay(client, message_parts, message):
741 member = data.db_get_member(message.author.id) 724 member = data.db_get_member(message.author.id)
742 if not member: 725 if not member:
743 client.send_message(message.author, "There was a problem looking up your information.") 726 send_message(client, message.author, "There was a problem looking up your information.")
744 elif type(message.channel) is not discord.channel.PrivateChannel: 727 elif type(message.channel) is not discord.channel.PrivateChannel:
745 client.send_message(message.author, "You must make all bets / gaming via private message.") 728 send_message(client, message.author, "You must make all bets / gaming via private message.")
746 else: 729 else:
747 state = data.db_get_minigame_state(member['member_id'], 'blackjack') 730 state = data.db_get_minigame_state(member['member_id'], 'blackjack')
748 if state: 731 if state:
...@@ -756,24 +739,24 @@ def do_bj_stay(client, message_parts, message): ...@@ -756,24 +739,24 @@ def do_bj_stay(client, message_parts, message):
756 log("{} - {}".format(member['member_name'], response.format(win,))) 739 log("{} - {}".format(member['member_name'], response.format(win,)))
757 result, error_message = data.db_update_credit(member['member_id'], int(win)) 740 result, error_message = data.db_update_credit(member['member_id'], int(win))
758 if not result: 741 if not result:
759 client.send_message(message.author, error_message) 742 send_message(client, message.author, error_message)
760 return 743 return
761 credits = data.db_get_credit(member['member_id']) 744 credits = data.db_get_credit(member['member_id'])
762 out_string += "\nCredits: {}".format(credits) 745 out_string += "\nCredits: {}".format(credits)
763 client.send_message(message.author, out_string) 746 send_message(client, message.author, out_string)
764 return 747 return
765 748
766 749
767 def do_bj_bet(client, message_parts, message): 750 def do_bj_bet(client, message_parts, message):
768 member = data.db_get_member(message.author.id) 751 member = data.db_get_member(message.author.id)
769 if not member: 752 if not member:
770 client.send_message(message.author, "There was a problem looking up your information.") 753 send_message(client, message.author, "There was a problem looking up your information.")
771 elif type(message.channel) is not discord.channel.PrivateChannel: 754 elif type(message.channel) is not discord.channel.PrivateChannel:
772 client.send_message(message.author, "You must make all bets / gaming via private message.") 755 send_message(client, message.author, "You must make all bets / gaming via private message.")
773 else: 756 else:
774 state = data.db_get_minigame_state(member['member_id'], 'blackjack') 757 state = data.db_get_minigame_state(member['member_id'], 'blackjack')
775 if state: 758 if state:
776 client.send_message(message.author, "You are already playing a game!") 759 send_message(client, message.author, "You are already playing a game!")
777 760
778 out_string = "" 761 out_string = ""
779 bj = pickle.loads(str(state)) 762 bj = pickle.loads(str(state))
...@@ -790,12 +773,12 @@ def do_bj_bet(client, message_parts, message): ...@@ -790,12 +773,12 @@ def do_bj_bet(client, message_parts, message):
790 log("{} - {}".format(member['member_name'], response.format(win,))) 773 log("{} - {}".format(member['member_name'], response.format(win,)))
791 result, error_message = data.db_update_credit(member['member_id'], int(win)) 774 result, error_message = data.db_update_credit(member['member_id'], int(win))
792 if not result: 775 if not result:
793 client.send_message(message.author, error_message) 776 send_message(client, message.author, error_message)
794 return 777 return
795 credits = data.db_get_credit(member['member_id']) 778 credits = data.db_get_credit(member['member_id'])
796 out_string += "\nCredits: {}".format(credits) 779 out_string += "\nCredits: {}".format(credits)
797 780
798 client.send_message(message.author, out_string) 781 send_message(client, message.author, out_string)
799 782
800 return 783 return
801 784
...@@ -804,12 +787,12 @@ def do_bj_bet(client, message_parts, message): ...@@ -804,12 +787,12 @@ def do_bj_bet(client, message_parts, message):
804 log("Member: {} Bet: {}".format(member['member_name'], bet_amount)) 787 log("Member: {} Bet: {}".format(member['member_name'], bet_amount))
805 788
806 if not bet_amount.isdigit(): 789 if not bet_amount.isdigit():
807 client.send_message(message.author, "Please provide a bet amount. !bet 10") 790 send_message(client, message.author, "Please provide a bet amount. !bet 10")
808 return 791 return
809 792
810 result, error_message = data.db_update_credit(member['member_id'], -int(bet_amount)) 793 result, error_message = data.db_update_credit(member['member_id'], -int(bet_amount))
811 if not result: 794 if not result:
812 client.send_message(message.author, error_message) 795 send_message(client, message.author, error_message)
813 return 796 return
814 out_string += "Welcome to BlackJack! :flower_playing_cards: You have placed a bet of: {}\n".format(bet_amount) 797 out_string += "Welcome to BlackJack! :flower_playing_cards: You have placed a bet of: {}\n".format(bet_amount)
815 bj = Blackjack(bet_amount) 798 bj = Blackjack(bet_amount)
...@@ -826,12 +809,12 @@ def do_bj_bet(client, message_parts, message): ...@@ -826,12 +809,12 @@ def do_bj_bet(client, message_parts, message):
826 log("{} - {}".format(member['member_name'], response.format(win,))) 809 log("{} - {}".format(member['member_name'], response.format(win,)))
827 result, error_message = data.db_update_credit(member['member_id'], int(win)) 810 result, error_message = data.db_update_credit(member['member_id'], int(win))
828 if not result: 811 if not result:
829 client.send_message(message.author, error_message) 812 send_message(client, message.author, error_message)
830 return 813 return
831 credits = data.db_get_credit(member['member_id']) 814 credits = data.db_get_credit(member['member_id'])
832 out_string += "\nCredits: {}".format(credits) 815 out_string += "\nCredits: {}".format(credits)
833 816
834 client.send_message(message.author, out_string) 817 send_message(client, message.author, out_string)
835 return 818 return
836 819
837 820
...@@ -862,7 +845,7 @@ def do_msg(client, message_parts, message): ...@@ -862,7 +845,7 @@ def do_msg(client, message_parts, message):
862 msg_datetime = tmp_date 845 msg_datetime = tmp_date
863 msg_idx = 4 846 msg_idx = 4
864 except ValueError: 847 except ValueError:
865 client.send_message(channel, 'Your shitty message has been rejected {}. Next time learn how to date...MM\\DD\\YYYY'.format(message.author.mention())) 848 send_message(client, channel, 'Your shitty message has been rejected {}. Next time learn how to date...MM\\DD\\YYYY'.format(message.author.mention()))
866 return 849 return
867 850
868 username = message_bits[1] 851 username = message_bits[1]
...@@ -872,8 +855,9 @@ def do_msg(client, message_parts, message): ...@@ -872,8 +855,9 @@ def do_msg(client, message_parts, message):
872 if username.lower() == member.name.lower(): 855 if username.lower() == member.name.lower():
873 user_mention = member.mention() 856 user_mention = member.mention()
874 user_id = member.id 857 user_id = member.id
858 break
875 if user_mention == '': 859 if user_mention == '':
876 client.send_message(channel, 'Your shitty message has been rejected {}. That user does not exist.'.format(message.author.name)) 860 send_message(client, channel, 'Your shitty message has been rejected {}. That user does not exist.'.format(message.author.name))
877 return 861 return
878 862
879 msg_text = byteify(' '.join(message_bits[msg_idx:])) 863 msg_text = byteify(' '.join(message_bits[msg_idx:]))
...@@ -884,13 +868,13 @@ def do_msg(client, message_parts, message): ...@@ -884,13 +868,13 @@ def do_msg(client, message_parts, message):
884 #test_ch = Object(channel.id) 868 #test_ch = Object(channel.id)
885 #client.send_message(test_ch, 'Test Message {}.'.format(author)) 869 #client.send_message(test_ch, 'Test Message {}.'.format(author))
886 except Exception as e: 870 except Exception as e:
887 client.send_message(channel, 'Your shitty message has been rejected {}. {}'.format(author.name, format_exception(e))) 871 send_message(client, channel, 'Your shitty message has been rejected {}. {}'.format(author.name, format_exception(e)))
888 return 872 return
889 if msg_datetime < datetime.datetime.now(): 873 if msg_datetime < datetime.datetime.now():
890 client.send_message(channel, '{} your message will be delivered to {} as soon as they are available.'.format(author.name, user_mention)) 874 send_message(client, channel, '{} your message will be delivered to {} as soon as they are available.'.format(author.name, user_mention))
891 else: 875 else:
892 client.send_message(channel, '{} your message will be delivered to {} {}.'.format(author.name, user_mention, human(msg_datetime))) 876 send_message(client, channel, '{} your message will be delivered to {} {}.'.format(author.name, user_mention, human(msg_datetime)))
893 check_msg_queue() 877 check_msg_queue(client)
894 return 878 return
895 879
896 880
...@@ -898,7 +882,7 @@ def do_addfortune(client, message_parts, message): ...@@ -898,7 +882,7 @@ def do_addfortune(client, message_parts, message):
898 try: 882 try:
899 fortune = message.content[9:] 883 fortune = message.content[9:]
900 if 'aa737a5846' in fortune: 884 if 'aa737a5846' in fortune:
901 client.send_message(message.channel, '{} you stop it, you are a pedofile, stop looking at little girls.'.format(message.author.mention())) 885 send_message(client, message.channel, '{} you stop it, you are a pedofile, stop looking at little girls.'.format(message.author.mention()))
902 return 886 return
903 date_added = datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S') 887 date_added = datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S')
904 c = conn.cursor() 888 c = conn.cursor()
...@@ -907,9 +891,9 @@ def do_addfortune(client, message_parts, message): ...@@ -907,9 +891,9 @@ def do_addfortune(client, message_parts, message):
907 log("Added fortune") 891 log("Added fortune")
908 except Exception as e: 892 except Exception as e:
909 log(e.message) 893 log(e.message)
910 client.send_message(message.channel, 'Your shitty fortune has been rejected {}.'.format(message.author.mention())) 894 send_message(client, message.channel, 'Your shitty fortune has been rejected {}.'.format(message.author.mention()))
911 return 895 return
912 client.send_message(message.channel, 'Your shitty fortune has been added {}.'.format(message.author.mention())) 896 send_message(client, message.channel, 'Your shitty fortune has been added {}.'.format(message.author.mention()))
913 return 897 return
914 898
915 899
...@@ -924,16 +908,16 @@ def do_fortune(client, message_parts, message): ...@@ -924,16 +908,16 @@ def do_fortune(client, message_parts, message):
924 log(e) 908 log(e)
925 pass 909 pass
926 if not fortune: 910 if not fortune:
927 client.send_message(message.channel, 'Try adding a fortune with "!addfortune <fortune>" {}!'.format(message.author.mention())) 911 send_message(client, message.channel, 'Try adding a fortune with "!addfortune <fortune>" {}!'.format(message.author.mention()))
928 else: 912 else:
929 client.send_message(message.channel, '{} Your fortune is... {}'.format(message.author.mention(), byteify(fortune))) 913 send_message(client, message.channel, '{} Your fortune is... {}'.format(message.author.mention(), byteify(fortune)))
930 return 914 return
931 915
932 916
933 def do_question(client, message_parts, message): 917 def do_question(client, message_parts, message):
934 question = message.content[10:] 918 question = message.content[10:]
935 if "is it gay" in question: 919 if "is it gay" in question:
936 client.send_message(message.channel, 'Yes {}, it is gay.'.format(message.author.mention())) 920 send_message(client, message.channel, 'Yes {}, it is gay.'.format(message.author.mention()))
937 return 921 return
938 res = wolf.query(question) 922 res = wolf.query(question)
939 try: 923 try:
...@@ -942,7 +926,7 @@ def do_question(client, message_parts, message): ...@@ -942,7 +926,7 @@ def do_question(client, message_parts, message):
942 for pod in res.pods: 926 for pod in res.pods:
943 if pod.text: 927 if pod.text:
944 pod_text.append(pod.text) 928 pod_text.append(pod.text)
945 client.send_message(message.channel, '{} {}.'.format(message.author.mention(), byteify("\n".join(pod_text)[:1990]))) 929 send_message(client, message.channel, '{} {}.'.format(message.author.mention(), byteify("\n".join(pod_text)[:1990])))
946 else: 930 else:
947 tagged_sent = pos_tag(question.replace('?', '').split()) 931 tagged_sent = pos_tag(question.replace('?', '').split())
948 proper_nouns = [word for word, pos in tagged_sent if pos == 'NNP'] 932 proper_nouns = [word for word, pos in tagged_sent if pos == 'NNP']
...@@ -950,13 +934,13 @@ def do_question(client, message_parts, message): ...@@ -950,13 +934,13 @@ def do_question(client, message_parts, message):
950 if wiki_search.strip() != "": 934 if wiki_search.strip() != "":
951 log("Looking up {}".format(wiki_search)) 935 log("Looking up {}".format(wiki_search))
952 wiki_out = wikipedia.summary(wiki_search, sentences=3) 936 wiki_out = wikipedia.summary(wiki_search, sentences=3)
953 client.send_message(message.channel, '{} {}.'.format(message.author.mention(), byteify(wiki_out))) 937 send_message(client, message.channel, '{} {}.'.format(message.author.mention(), byteify(wiki_out)))
954 else: 938 else:
955 client.send_message(message.channel, 'I don\'t know {}.'.format(message.author.mention())) 939 send_message(client, message.channel, 'I don\'t know {}.'.format(message.author.mention()))
956 return 940 return
957 except Exception as e: 941 except Exception as e:
958 log(format_exception(e)) 942 log(format_exception(e))
959 client.send_message(message.channel, 'I don\'t know {}.'.format(message.author.mention())) 943 send_message(client, message.channel, 'I don\'t know {}.'.format(message.author.mention()))
960 return 944 return
961 945
962 946
...@@ -964,7 +948,7 @@ def do_addjoke(client, message_parts, message): ...@@ -964,7 +948,7 @@ def do_addjoke(client, message_parts, message):
964 try: 948 try:
965 joke = message.content[9:] 949 joke = message.content[9:]
966 if 'aa737a5846' in joke: 950 if 'aa737a5846' in joke:
967 client.send_message(message.channel, '{} you stop it, you are a pedofile, stop looking at little girls.'.format(message.author.mention())) 951 send_message(client, message.channel, '{} you stop it, you are a pedofile, stop looking at little girls.'.format(message.author.mention()))
968 return 952 return
969 c = conn.cursor() 953 c = conn.cursor()
970 c.execute("INSERT INTO jokes (joke) VALUES (?)", (joke,)) 954 c.execute("INSERT INTO jokes (joke) VALUES (?)", (joke,))
...@@ -972,9 +956,9 @@ def do_addjoke(client, message_parts, message): ...@@ -972,9 +956,9 @@ def do_addjoke(client, message_parts, message):
972 log("Added joke") 956 log("Added joke")
973 except Exception as e: 957 except Exception as e:
974 log(e.message) 958 log(e.message)
975 client.send_message(message.channel, 'Your shitty joke has been rejected {}.'.format(message.author.mention())) 959 send_message(client, message.channel, 'Your shitty joke has been rejected {}.'.format(message.author.mention()))
976 return 960 return
977 client.send_message(message.channel, 'Your shitty joke has been added {}.'.format(message.author.mention())) 961 send_message(client, message.channel, 'Your shitty joke has been added {}.'.format(message.author.mention()))
978 return 962 return
979 963
980 964
...@@ -988,40 +972,40 @@ def do_joke(client, message_parts, message): ...@@ -988,40 +972,40 @@ def do_joke(client, message_parts, message):
988 log(e) 972 log(e)
989 pass 973 pass
990 if not joke: 974 if not joke:
991 client.send_message(message.channel, 'Try adding a joke with "!addjoke <joke>" {}!'.format(message.author.mention())) 975 send_message(client, message.channel, 'Try adding a joke with "!addjoke <joke>" {}!'.format(message.author.mention()))
992 else: 976 else:
993 client.send_message(message.channel, '{} {}'.format(message.author.mention(), byteify(joke))) 977 send_message(client, message.channel, '{} {}'.format(message.author.mention(), byteify(joke)))
994 return 978 return
995 979
996 980
997 def do_secret(client, message_parts, message): 981 def do_secret(client, message_parts, message):
998 client.send_message(message.channel, 'git gud {}! My source is here: http://git.savsoul.com/barry/discordbot\nVersion: {}'.format(message.author.mention(), VERSION)) 982 send_message(client, message.channel, 'git gud {}! My source is here: http://git.savsoul.com/barry/discordbot\nVersion: {}'.format(message.author.mention(), VERSION))
999 return 983 return
1000 984
1001 985
1002 def do_waifu(client, message_parts, message): 986 def do_waifu(client, message_parts, message):
1003 client.send_message(message.channel, 'http://orig13.deviantart.net/b25e/f/2014/175/3/d/no_waifu_no_laifu_by_imtheonenexttome-d7nsx3b.gif {}!'.format(message.author.mention())) 987 send_message(client, message.channel, 'http://orig13.deviantart.net/b25e/f/2014/175/3/d/no_waifu_no_laifu_by_imtheonenexttome-d7nsx3b.gif {}!'.format(message.author.mention()))
1004 return 988 return
1005 989
1006 990
1007 def do_hillary(client, message_parts, message): 991 def do_hillary(client, message_parts, message):
1008 client.send_message(message.channel, ':bomb: Ohhhhhh, now you done it...:bomb:'.format(message.author.mention())) 992 send_message(client, message.channel, ':bomb: Ohhhhhh, now you done it...:bomb:'.format(message.author.mention()))
1009 return 993 return
1010 994
1011 995
1012 def do_squid(client, message_parts, message): 996 def do_squid(client, message_parts, message):
1013 client.send_message(message.channel, 'くコ:彡 くコ:彡 くコ:彡 くコ:彡') 997 send_message(client, message.channel, 'くコ:彡 くコ:彡 くコ:彡 くコ:彡')
1014 return 998 return
1015 999
1016 1000
1017 def do_stars(client, message_parts, message): 1001 def do_stars(client, message_parts, message):
1018 client.send_message(message.channel, '✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈ ✰═━┈┈ ✰═━┈┈') 1002 send_message(client, message.channel, '✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈ ✰═━┈┈ ✰═━┈┈')
1019 return 1003 return
1020 1004
1021 1005
1022 def do_rigged(client, message_parts, message): 1006 def do_rigged(client, message_parts, message):
1023 lines = open('studylyrics.txt').read().splitlines() 1007 lines = open('studylyrics.txt').read().splitlines()
1024 client.send_message(message.channel, ":musical_note: {} :musical_note:".format(random.choice(lines))) 1008 send_message(client, message.channel, ":musical_note: {} :musical_note:".format(random.choice(lines)))
1025 return 1009 return
1026 1010
1027 def start_timer(client): 1011 def start_timer(client):
...@@ -1036,17 +1020,42 @@ def start_timer(client): ...@@ -1036,17 +1020,42 @@ def start_timer(client):
1036 do_grantcredits(client, None, None, channel) 1020 do_grantcredits(client, None, None, channel)
1037 needs_loot = False 1021 needs_loot = False
1038 time.sleep(10000) 1022 time.sleep(10000)
1039 log('Sleeping') 1023 #log('Sleeping')
1040 1024
1041 def thread_exception_handler(method, client, message_parts, message): 1025 def thread_exception_handler(method, client, message_parts, message):
1042 try: 1026 try:
1043 if message: 1027 if message:
1044 globals()[method](client, message_parts[1:], message) 1028 globals()[method](client, message_parts, message)
1045 else: 1029 else:
1046 globals()[method](client) 1030 globals()[method](client)
1047 except Exception as e: 1031 except Exception as e:
1048 log("{} - {}".format(format_exception(e), e.message)) 1032 log("{} - {}".format(format_exception(e), e.message))
1049 1033
1034 #################
1035 # Client Events
1036 #################
1037 @client.event
1038 def on_socket_raw_send(payload, binary=False):
1039 check_msg_queue(client)
1040
1041
1042 @client.event
1043 def on_status(member):
1044 for member in client.get_all_members():
1045 try:
1046 db_member = data.db_get_member(member.id)
1047
1048 if not db_member:
1049 log("Creating new member: {}".format(member))
1050 data.db_create_member(member)
1051 else:
1052 data.db_update_member(member, db_member)
1053
1054 check_msg_queue(client)
1055 except Exception as e:
1056 log("Exception: {}".format(format_exception(e)))
1057 pass
1058
1050 @client.event 1059 @client.event
1051 def on_message(message): 1060 def on_message(message):
1052 #print message.content 1061 #print message.content
...@@ -1070,7 +1079,7 @@ def on_message(message): ...@@ -1070,7 +1079,7 @@ def on_message(message):
1070 log('Someone is talking to %s' % (client.user.name.lower(),)) 1079 log('Someone is talking to %s' % (client.user.name.lower(),))
1071 if ' or ' in message.content: 1080 if ' or ' in message.content:
1072 questions = message.content[len(client.user.name)+1:].replace('?', '').split(' or ') 1081 questions = message.content[len(client.user.name)+1:].replace('?', '').split(' or ')
1073 client.send_message(message.channel, '{} I choose: {}'.format(message.author.mention(), random.choice(questions).encode('utf-8', errors='ignore'))) 1082 send_message(client, message.channel, '{} I choose: {}'.format(message.author.mention(), random.choice(questions).encode('utf-8', errors='ignore')))
1074 1083
1075 1084
1076 @client.event 1085 @client.event
...@@ -1081,12 +1090,13 @@ def on_ready(): ...@@ -1081,12 +1090,13 @@ def on_ready():
1081 log('------') 1090 log('------')
1082 for member in client.get_all_members(): 1091 for member in client.get_all_members():
1083 if member.id == '78767557628133376': 1092 if member.id == '78767557628133376':
1084 client.send_message(member, "Bot Started") 1093 send_message(client, member, "Bot Started")
1094 break
1085 # for channel in client.get_all_channels(): 1095 # for channel in client.get_all_channels():
1086 # client.send_message(member, "Bot Started {} {}".format(channel.id, channel.name)) 1096 # client.send_message(member, "Bot Started {} {}".format(channel.id, channel.name))
1087 1097
1088 check_msg_queue() 1098 check_msg_queue(client)
1089 1099
1090 thread.start_new_thread(thread_exception_handler, ('start_timer', client, None, None)) 1100 thread.start_new_thread(thread_exception_handler, ('start_timer', client, None, None))
1091 1101
1092 retries = 0 1102 retries = 0
......
1 import random 1 import random
2 import time 2 import time
3 import pickle 3 import pickle
4 import math
4 5
5 FIND_PERCENTAGE = 100 6 FIND_PERCENTAGE = 100
6 SKILL_PERCENT = 80 7 SKILL_PERCENT = 80
...@@ -15,8 +16,41 @@ class HuntResponse: ...@@ -15,8 +16,41 @@ class HuntResponse:
15 self.message = message 16 self.message = message
16 self.monster = monster 17 self.monster = monster
17 18
18 exp_to_level = [500, 1250, 2250, 3500, 5000, 6750, 8750, 10950, 13350, 15950, 18750, 21750, 24950, 28350, 31950, 35750, 39750, 43950, 48350, 52950, 57750, 62750, 67850, 73050, 78350, 83750, 89250, 94850, 100550, 106350, 112250, 118250, 124350, 130550, 136850, 143250, 149750, 156350, 163050, 169850, 176750, 183750, 190850, 198050, 205350, 212750, 220250, 227850, 235550] 19 exp_to_level = [0, 500, 1250, 2250, 3500, 5000, 6750, 8750, 10950, 13350, 15950, 18750, 21750, 24950, 28350, 31950, 35750, 39750, 43950, 48350, 52950, 57750, 62750, 67850, 73050, 78350, 83750, 89250, 94850, 100550, 106350, 112250, 118250, 124350, 130550, 136850, 143250, 149750, 156350, 163050, 169850, 176750, 183750, 190850, 198050, 205350, 212750, 220250, 227850, 235550, 243350]
19 20
21 exp_table = {
22 15: 600,
23 14: 600,
24 13: 600,
25 12: 600,
26 11: 600,
27 10: 600,
28 9: 600,
29 8: 600,
30 7: 550,
31 6: 450,
32 5: 350,
33 4: 300,
34 3: 240,
35 2: 220,
36 1: 210,
37 0: 200,
38 -1: 180,
39 -2: 160,
40 -3: 150,
41 -4: 140,
42 -5: 130,
43 -6: 120,
44 -7: 110,
45 -8: 100,
46 -9: 80,
47 -10: 60,
48 -11: 40,
49 -12: 40,
50 -13: 40,
51 -14: 40,
52 -15: 40,
53 }
20 class Jobs: 54 class Jobs:
21 WAR = 1 55 WAR = 1
22 MNK = 2 56 MNK = 2
...@@ -85,6 +119,12 @@ Families = { ...@@ -85,6 +119,12 @@ Families = {
85 'charmable': False, 119 'charmable': False,
86 'aspir': False, 120 'aspir': False,
87 'drain': False, 121 'drain': False,
122 'base_vit': 10,
123 'vit_per_level': 0.9334,
124 'base_str': 9,
125 'str_per_level': 0.8934,
126 'base_agi': 7,
127 'agi_per_level': 0.76,
88 'temperament_attitude': { 128 'temperament_attitude': {
89 'initial_value': 4, 129 'initial_value': 4,
90 'actions': { 130 'actions': {
...@@ -116,6 +156,12 @@ Families = { ...@@ -116,6 +156,12 @@ Families = {
116 'charmable': False, 156 'charmable': False,
117 'aspir': True, 157 'aspir': True,
118 'drain': True, 158 'drain': True,
159 'base_vit': 8,
160 'vit_per_level': 0.8,
161 'base_str': 8,
162 'str_per_level': 0.8534,
163 'base_agi': 9,
164 'agi_per_level': 0.88,
119 'temperament_attitude': { 165 'temperament_attitude': {
120 'initial_value': 4, 166 'initial_value': 4,
121 'actions': { 167 'actions': {
...@@ -141,12 +187,16 @@ Monsters = { ...@@ -141,12 +187,16 @@ Monsters = {
141 'Mechanical Menace': { 187 'Mechanical Menace': {
142 'initial_level': 9, 188 'initial_level': 9,
143 'family': 'acrolith', 189 'family': 'acrolith',
144 'zone': 'Abyssea - Uleguerand' 190 'zone': 'Abyssea - Uleguerand',
191 'hp': 1000,
192 'weapon_base_damage': 40
145 }, 193 },
146 'Floating Eye': { 194 'Floating Eye': {
147 'initial_level': 3, 195 'initial_level': 3,
148 'family': 'ahriman', 196 'family': 'ahriman',
149 'zone': 'Ranguemont Pass' 197 'zone': 'Ranguemont Pass',
198 'hp': 1000,
199 'weapon_base_damage': 120
150 } 200 }
151 } 201 }
152 202
...@@ -156,7 +206,7 @@ class Pankration: ...@@ -156,7 +206,7 @@ class Pankration:
156 pass 206 pass
157 207
158 def start_battle(self, monster1, monster2, battle_type): 208 def start_battle(self, monster1, monster2, battle_type):
159 battle = Battle(monster1, monster2, battle_type) 209 battle = Arena(monster1, monster2, battle_type)
160 battle.start() 210 battle.start()
161 return battle 211 return battle
162 212
...@@ -176,8 +226,11 @@ class Pankration: ...@@ -176,8 +226,11 @@ class Pankration:
176 226
177 def hunt_monster(self, zone): 227 def hunt_monster(self, zone):
178 if random.randint(1, 100) < FIND_PERCENTAGE: 228 if random.randint(1, 100) < FIND_PERCENTAGE:
179 monster_data = Monsters[random.choice(self.get_monsters(zone))] 229 monster_name = random.choice(self.get_monsters(zone))
180 print(monster_data) 230 monster_data = Monsters[monster_name]
231 hp = monster_data['hp']
232 weapon_base_damage = monster_data['weapon_base_damage']
233 print("Monster: {} Data: {}".format(monster_name, monster_data))
181 family_name = monster_data['family'] 234 family_name = monster_data['family']
182 level = monster_data['initial_level'] 235 level = monster_data['initial_level']
183 family = Families[family_name] 236 family = Families[family_name]
...@@ -193,7 +246,7 @@ class Pankration: ...@@ -193,7 +246,7 @@ class Pankration:
193 feral_skills.append(skills[2]) 246 feral_skills.append(skills[2])
194 dicipline_level = 1 247 dicipline_level = 1
195 248
196 monster = Monster(family, level, main_job, support_job, feral_skills, 249 monster = Monster(monster_name, family, hp, level, weapon_base_damage, main_job, support_job, feral_skills,
197 [], dicipline_level) 250 [], dicipline_level)
198 return HuntResponse(HuntResponse.SUCCESS, "You captured the monster!", 251 return HuntResponse(HuntResponse.SUCCESS, "You captured the monster!",
199 monster) 252 monster)
...@@ -206,9 +259,12 @@ class Pankration: ...@@ -206,9 +259,12 @@ class Pankration:
206 259
207 260
208 class Monster: 261 class Monster:
209 def __init__(self, family, level, main_job, support_job, innate_feral_skills, 262 def __init__(self, monster_type, family, hp, level, weapon_base_damage, main_job, support_job, innate_feral_skills,
210 equipped_feral_skills, dicipline_level): 263 equipped_feral_skills, dicipline_level):
264 self.monster_type = monster_type
211 self.family = family 265 self.family = family
266 self.max_hp = hp
267 self.hp = hp
212 self.level = level 268 self.level = level
213 self.main_job = main_job 269 self.main_job = main_job
214 self.support_job = support_job 270 self.support_job = support_job
...@@ -220,8 +276,14 @@ class Monster: ...@@ -220,8 +276,14 @@ class Monster:
220 self.pre_fight_command = {"temperament_posture": None, "temperament_attitude": None} 276 self.pre_fight_command = {"temperament_posture": None, "temperament_attitude": None}
221 self.exp = exp_to_level[level] + 1 277 self.exp = exp_to_level[level] + 1
222 # TODO: Setup something more interesting for each monster. 278 # TODO: Setup something more interesting for each monster.
223 self.weapon_base_damage = 43 279 self.weapon_base_damage = weapon_base_damage
224 self.ammo_damage = 0 280 self.ammo_damage = 0
281 self.base_vit = family['base_vit']
282 self.vit_per_level = family['vit_per_level']
283 self.base_str = family['base_str']
284 self.str_per_level = family['str_per_level']
285 self.base_agi = family['base_agi']
286 self.agi_per_level = family['agi_per_level']
225 287
226 def __str__(self): 288 def __str__(self):
227 return "Family: {}\nLevel: {}\nMain Job: {}\nSupport Job: {}\nInnate Feral Skills: {}\nEquipped Feral Skills: {}\nDicipline Level: {}\nTemperament...".format(self.family, self.level, self.main_job, self.support_job, self.innate_feral_skills, self.equipped_feral_skills, self.discipline_level) 289 return "Family: {}\nLevel: {}\nMain Job: {}\nSupport Job: {}\nInnate Feral Skills: {}\nEquipped Feral Skills: {}\nDicipline Level: {}\nTemperament...".format(self.family, self.level, self.main_job, self.support_job, self.innate_feral_skills, self.equipped_feral_skills, self.discipline_level)
...@@ -231,13 +293,14 @@ class Monster: ...@@ -231,13 +293,14 @@ class Monster:
231 293
232 def add_xp(self, exp_to_add): 294 def add_xp(self, exp_to_add):
233 self.exp += exp_to_add 295 self.exp += exp_to_add
234 for i in range(self.level, 50): 296 for i in range(self.level, 51):
235 if self.exp > exp_to_level[i]: 297 if self.exp > exp_to_level[i]:
236 if i > self.level: 298 if i > self.level:
237 # We leveled up! 299 # We leveled up!
238 print("Start level: {} New Level: {}".format(self.level, i)) 300 self.level = i
301 #print("Start level: {} New Level: {}".format(self.level, i))
239 else: 302 else:
240 print("Just another brick in the wall...") 303 pass#print("Just another brick in the wall...")
241 else: 304 else:
242 break 305 break
243 # calc level based on xp 306 # calc level based on xp
...@@ -260,9 +323,25 @@ class Monster: ...@@ -260,9 +323,25 @@ class Monster:
260 else: 323 else:
261 return "Obedient" 324 return "Obedient"
262 325
326 def get_vitality(self):
327 return int(round(max(self.base_vit, self.level * self.vit_per_level)))
328
329 def get_strength(self):
330 return int(round(max(self.base_str, self.level * self.str_per_level)))
331
332 def get_agility(self):
333 return int(round(max(self.base_agi, self.level * self.agi_per_level)))
334
335 def get_base_defense(self):
336 return (math.floor(self.get_vitality()/2) + 8 + self.level)
337
338 def get_hp_percent(self):
339 return max(0, int(round((self.hp/self.max_hp)*100)))
340
263 # Calculate the base damage against the provided defense 341 # Calculate the base damage against the provided defense
264 # attack_type can be 'ranged' or 'melee' 342 # attack_type can be 'ranged' or 'melee'
265 def get_physical_base_damage(self, defense, attack_type, level_difference): 343 def get_physical_base_damage(self, defense, attack_type, level_difference):
344 #print("Defense: {} Type: {} Level diff: {}".format(defense, attack_type, level_difference))
266 # Calculate the attack/defense ratio 345 # Calculate the attack/defense ratio
267 bd = float(self.weapon_base_damage) 346 bd = float(self.weapon_base_damage)
268 if attack_type == 'ranged': 347 if attack_type == 'ranged':
...@@ -285,8 +364,12 @@ class Monster: ...@@ -285,8 +364,12 @@ class Monster:
285 cRatio = ratio - 0.050 * level_difference 364 cRatio = ratio - 0.050 * level_difference
286 if cRatio < 0: 365 if cRatio < 0:
287 cRatio = 0 366 cRatio = 0
288 if cRatio > 3.0: 367 if attack_type == 'ranged':
289 cRatio = 3.0 368 if cRatio > 3.0:
369 cRatio = 3.0
370 else:
371 if cRatio > 2.25:
372 cRatio = 2.25
290 # Calculate the pDif max as the max of our RNG 373 # Calculate the pDif max as the max of our RNG
291 if cRatio <= 0.5: 374 if cRatio <= 0.5:
292 pDif_max = 1+(10/9)*(cRatio-0.5) 375 pDif_max = 1+(10/9)*(cRatio-0.5)
...@@ -305,13 +388,21 @@ class Monster: ...@@ -305,13 +388,21 @@ class Monster:
305 elif 1.5 <= cRatio <= cap: 388 elif 1.5 <= cRatio <= cap:
306 pDif_min = 1+(10/9)*(cRatio-1.5) 389 pDif_min = 1+(10/9)*(cRatio-1.5)
307 390
308 print(pDif_min)
309 # Some fuckery since python doesn't let you do a rand between decimals 391 # Some fuckery since python doesn't let you do a rand between decimals
310 pDif_rand = float(random.randint(int(pDif_min*100000), int(pDif_max*100000))) / 100000.0 392 pDif_rand = float(random.randint(int(pDif_min*100000), int(pDif_max*100000))) / 100000.0
311 393
312 final_damage = bd * (pDif_rand * cRatio) 394 final_damage = bd * (pDif_rand * cRatio)
313 return final_damage 395 return final_damage
314 396
397 def attack(self, monster):
398 phy_damage = self.get_physical_base_damage(monster.get_base_defense(), 'melee', monster.level - self.level)
399 return (phy_damage, 'hits')
400
401
402 def apply_damage(self, damage):
403 self.hp -= damage
404 # Check life and return 'awesome', 'fucked up', 'dead' or something
405
315 # This should ONLY be executed at the start of battle. 406 # This should ONLY be executed at the start of battle.
316 def set_strategy(self, temperament_posture, temperament_attitude): 407 def set_strategy(self, temperament_posture, temperament_attitude):
317 distance_from_nature = abs(self.temperament_posture - temperament_posture) 408 distance_from_nature = abs(self.temperament_posture - temperament_posture)
...@@ -333,19 +424,64 @@ class Monster: ...@@ -333,19 +424,64 @@ class Monster:
333 #if severe request then reduce dicipline_level 424 #if severe request then reduce dicipline_level
334 pass 425 pass
335 426
427 class Action:
428 def __init__(self, monster):
429 self.monster = monster
430
431 class AttackAction(Action):
432 def __init__(self, attacker, target, damage, message):
433 self.attacker = attacker
434 self.target = target
435 self.damage = damage
436 self.message = message
437
438 class DefeatAction(Action):
439 def __init__(self, attacker, target, message, xp):
440 self.attacker = attacker
441 self.target = target
442 self.message = message
443 self.xp = xp
444
445 class Arena:
336 446
337 class Battle:
338 def __init__(self, monster1, monster2, battle_type): 447 def __init__(self, monster1, monster2, battle_type):
339 self.monster1 = monster1 448 self.monster1 = monster1
340 self.monster2 = monster2 449 self.monster2 = monster2
341 self.battle_type = battle_type 450 self.battle_type = battle_type
342 451
343 def perform_attack(): 452 def heal_monsters(self):
344 base_damage = get_physical_base_damage(monster2.defense, 'melee', 0) 453 pass
454
455 def start(self):
456 self.heal_monsters()
457 self.m1_init = self.monster1.get_agility() + random.randint(1, 20)
458 self.m2_init = self.monster2.get_agility() + random.randint(1, 20)
345 459
460 def step(self):
461 actions = []
462 if self.m1_init > self.m2_init:
463 primary = self.monster1
464 secondary = self.monster2
465 else:
466 primary = self.monster2
467 secondary = self.monster1
468
469 result1 = primary.attack(secondary)
470 secondary.apply_damage(result1[0])
471 actions.append(AttackAction(primary, secondary, result1[0], result1[1]))
472 if secondary.hp <= 0:
473 xp = 200 + (20 * (primary.level - secondary.level))
474 actions.append(DefeatAction(secondary, primary, 'was defeated', xp))
475 return actions
476 result2 = secondary.attack(primary)
477 primary.apply_damage(result2[0])
478 actions.append(AttackAction(secondary, primary, result2[0], result2[1]))
479 if primary.hp <= 0:
480 xp = 200 + (20 * (secondary.level - primary.level))
481 actions.append(DefeatAction(primary, secondary, 'was defeated', xp))
482 return actions
483 return actions
346 484
347 class Arena:
348 pass
349 485
350 #print Families 486 #print Families
351 487
...@@ -360,26 +496,46 @@ time.sleep(0.5) ...@@ -360,26 +496,46 @@ time.sleep(0.5)
360 if hunt_response.result == HuntResponse.SUCCESS: 496 if hunt_response.result == HuntResponse.SUCCESS:
361 print(hunt_response.message) 497 print(hunt_response.message)
362 monster = hunt_response.monster 498 monster = hunt_response.monster
363 print("The Soul Plate Shows: \n\n{}".format(monster)) 499 # print("The Soul Plate Shows: \n\n{}".format(monster))
364 print(monster.set_strategy(4, 3)) 500 # print(monster.set_strategy(4, 3))
365 print(monster.set_strategy(1, 1)) 501 # print(monster.set_strategy(1, 1))
366 print(monster.set_strategy(1, 2)) 502 # print(monster.set_strategy(1, 2))
367 monster.add_xp(2900) 503 #monster.add_xp(22900)
368 phy_damage = monster.get_physical_base_damage(100, 'melee', -15) 504 # phy_damage = monster.get_physical_base_damage(100, 'melee', -15)
369 print("Phys Attack: {}".format(phy_damage)) 505 # print("Phys Attack: {}".format(phy_damage))
506 # print(monster.get_base_defense())
507 # monster.add_xp(22900)
508 # print(monster.get_base_defense())
509 # monster.add_xp(222900)
510 # print(monster.get_base_defense())
370 else: 511 else:
371 print(hunt_response.message) 512 print(hunt_response.message)
372 513
373 514
515 hunt_zone = p.list_zones()[1]
516 hunt_response = p.hunt_monster(hunt_zone)
517 if hunt_response.result == HuntResponse.SUCCESS:
518 monster2 = hunt_response.monster
519 monster2.add_xp(16900)
520 phy_damage = monster2.attack(monster)
521 print("Phys Attack: {}".format(phy_damage))
374 522
375 523
376 524
377 525
378 526 battle_arena = p.start_battle(monster, monster2, "derp")
379 527 fighting = True
380 528 while fighting:
381 529 actions = battle_arena.step()
382 530 time.sleep(2)
531 for action in actions:
532 if isinstance(action, AttackAction):
533 print("{} {} {} for {}.".format(action.attacker.monster_type, action.message, action.target.monster_type, action.damage))
534 if isinstance(action, DefeatAction):
535 print("{} {}. {} gains {} xp.".format(action.target.monster_type, action.message, action.attacker.monster_type, action.xp))
536 fighting = False
537 break
538 print("\n{} {}% - {} {}%\n".format(monster.monster_type, monster.get_hp_percent(), monster2.monster_type, monster2.get_hp_percent()))
383 539
384 540
385 541
......