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
from blackjack import Blackjack
import data
VERSION = 2.2
VERSION = 2.3
quitting = False
......@@ -94,6 +94,13 @@ def log(message):
except:
pass
def send_message(client, target, message):
if type(target) is not discord.channel.PrivateChannel:
if target.id == '121468616414724100':
return
elif datetime.datetime.now() < muted_until:
return
client.send_message(target, message)
def format_exception(e):
exception_list = traceback.format_stack()
......@@ -155,33 +162,7 @@ def search_google_images(query, animated=False):
return "boo you fail.."
#################
# Client Events
#################
@client.event
def on_socket_raw_send(payload, binary=False):
check_msg_queue()
@client.event
def on_status(member):
for member in client.get_all_members():
try:
db_member = data.db_get_member(member.id)
if not db_member:
log("Creating new member: {}".format(member))
data.db_create_member(member)
else:
data.db_update_member(member, db_member)
check_msg_queue()
except Exception as e:
log("Exception: {}".format(format_exception(e)))
pass
def check_msg_queue():
def check_msg_queue(client):
messages = data.db_get_messages()
if messages:
for message in messages:
......@@ -210,17 +191,17 @@ def do_roll(client, message_parts, message):
count = int(dice_parts[0])
dice = int(dice_parts[1])
if count > 100000000000000000:
client.send_message(message.channel, '{} stop fucking around with those stupid numbers...'.format(message.author.mention()))
send_message(client, message.channel, '{} stop fucking around with those stupid numbers...'.format(message.author.mention()))
return
if count > 100:
client.send_message(message.channel, '{} 100 is the largest number of dice I will roll.'.format(message.author.mention()))
send_message(client, message.channel, '{} 100 is the largest number of dice I will roll.'.format(message.author.mention()))
return
roll_results = []
for i in range(count):
roll_results.append(random.randint(1, dice))
out_string = '{} your roll {}d{}: {} = {}'.format(message.author.mention(), count, dice, '+'.join(str(r) for r in roll_results), sum(roll_results))
client.send_message(message.channel, out_string)
send_message(client, message.channel, out_string)
return
......@@ -240,14 +221,14 @@ def do_lastseen(client, message_parts, message):
human(datetime.datetime.strptime(member['status_change_at'], '%Y/%m/%d %H:%M:%S')),
member['prev_status'])
client.send_message(message.channel, 'Last Information on {}:\n{}'.format(byteify(username), out_string))
send_message(client, message.channel, 'Last Information on {}:\n{}'.format(byteify(username), out_string))
else:
client.send_message(message.channel, 'I don\'t have any data on {} yet {}'.format(byteify(username), message.author.mention()))
send_message(client, message.channel, 'I don\'t have any data on {} yet {}'.format(byteify(username), message.author.mention()))
return
def do_help(client, message_parts, message):
client.send_message(message.channel, """{} Available Commands:
send_message(client, message.channel, """{} Available Commands:
You can ask compound or questions and I will choose. Example: HellsBot Rui is a Faggot or Rui is a faggot?
User Info:
......@@ -270,7 +251,7 @@ Minigames:
!hit - Draw a card
!stand - Show the cards
""".format(message.author.mention()))
client.send_message(message.channel, """
send_message(client, message.channel, """
!balance - Lists your current credits and tickets
!buyticket - Purchases a raffle ticket for 100 credits
!raffle - Shows information about the current raffle
......@@ -294,33 +275,34 @@ Stuff:
def do_shutup(client, message_parts, message):
global muted_until
muted_until = datetime.datetime.now() + datetime.timedelta(minutes=5)
client.send_message(message.channel, 'All image / gif / youtube spam disabled for 5 minutes')
send_message(client, message.channel, 'All image / gif / youtube spam disabled for 5 minutes')
return
def do_youtube(client, message_parts, message):
if datetime.datetime.now() < muted_until:
return
client.send_message(message.channel, search_youtube(' '.join(message_parts)))
send_message(client, message.channel, search_youtube(' '.join(message_parts)))
return
def do_image(client, message_parts, message):
if datetime.datetime.now() < muted_until:
return
client.send_message(message.channel, search_google_images(' '.join(message_parts)))
send_message(client, message.channel, search_google_images(' '.join(message_parts)))
return
def do_gif(client, message_parts, message):
if datetime.datetime.now() < muted_until:
return
client.send_message(message.channel, search_google_images(' '.join(message_parts), True))
send_message(client, message.channel, search_google_images(' '.join(message_parts), True))
return
def do_gameslist(client, message_parts, message):
limit = 20
log("parts: {} {}".format(message_parts,message))
if len(message_parts) > 0 and message_parts[0].isdigit():
limit = int(message_parts[0])
games_list = data.db_get_games_list(limit)
......@@ -328,9 +310,9 @@ def do_gameslist(client, message_parts, message):
out_string = ''
for game in games_list:
out_string += ' {} - {}\n'.format(game[1], byteify(game[0]))
client.send_message(message.channel, 'The games I have seen people playing are: ')
send_message(client, message.channel, 'The games I have seen people playing are: ')
while len(out_string) > 0:
client.send_message(message.channel, out_string[:1900])
send_message(client, message.channel, out_string[:1900])
out_string = out_string[1900:]
return
......@@ -345,11 +327,11 @@ def do_alias(client, message_parts, message):
if member:
aliases = data.db_get_aliases(member['member_id'])
if aliases:
client.send_message(message.channel, '{} has the following aliases: {}'.format(byteify(username), byteify(', '.join(aliases))))
send_message(client, message.channel, '{} has the following aliases: {}'.format(byteify(username), byteify(', '.join(aliases))))
else:
client.send_message(message.channel, 'No known alises for {} yet {}'.format(byteify(username), message.author.mention()))
send_message(client, message.channel, 'No known alises for {} yet {}'.format(byteify(username), message.author.mention()))
else:
client.send_message(message.channel, 'I don\'t know who you are speaking of {}!'.format(message.author.mention()))
send_message(client, message.channel, 'I don\'t know who you are speaking of {}!'.format(message.author.mention()))
return
......@@ -359,9 +341,9 @@ def do_addalias(client, message_parts, message):
member = data.db_get_member(username=username)
if member:
data.db_add_aliases(member['member_id'], alias)
client.send_message(message.channel, '{} has been added to your aliases'.format(byteify(alias)))
send_message(client, message.channel, '{} has been added to your aliases'.format(byteify(alias)))
else:
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...)')
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...)')
return
......@@ -375,14 +357,14 @@ def do_games(client, message_parts, message):
games = ', '.join(games_list)
games = games.replace("FINAL FANTASY XIV", "**FINAL FANTASY XIV**")
log(byteify(games))
client.send_message(message.channel, 'I have seen {} playing: {}'.format(byteify(username), byteify(games)))
send_message(client, message.channel, 'I have seen {} playing: {}'.format(byteify(username), byteify(games)))
else:
client.send_message(message.channel, 'I don\'t have any data on {} yet {}'.format(byteify(username), message.author.mention()))
send_message(client, message.channel, 'I don\'t have any data on {} yet {}'.format(byteify(username), message.author.mention()))
def do_reload(client, message_parts, message):
if message.author.id != '78767557628133376':
client.send_message(message.channel, "You shouldn't be calling this. You are clearly looking to piss Hellsbreath off.")
send_message(client, message.channel, "You shouldn't be calling this. You are clearly looking to piss Hellsbreath off.")
return
call(["service", "hellsbot", "restart"])
......@@ -391,14 +373,14 @@ def do_whoplayed(client, message_parts, message):
game_name = ' '.join(message_parts)
member_list = data.db_get_whoplayed(game_name)
if not member_list:
client.send_message(message.channel, 'I don\'t have any data on {} yet {}'.format(byteify(game_name), message.author.mention()))
send_message(client, message.channel, 'I don\'t have any data on {} yet {}'.format(byteify(game_name), message.author.mention()))
else:
out_string = ''
for member in member_list:
out_string += ' {} - {}\n'.format(byteify(member[1]), byteify(member[0]))
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),))
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),))
while len(out_string) > 0:
client.send_message(message.channel, out_string[:1900])
send_message(client, message.channel, out_string[:1900])
out_string = out_string[1900:]
return
......@@ -406,48 +388,48 @@ def do_whoplayed(client, message_parts, message):
def do_gimmecredits(client, message_parts, message):
member = data.db_get_member(message.author.id)
if not member:
client.send_message(message.author, "There was a problem looking up your information.")
send_message(client, message.author, "There was a problem looking up your information.")
else:
credits = data.db_get_credit(member['member_id'])
if credits < 5:
amount = random.randint(5, 50)
data.db_update_credit(member['member_id'], amount)
client.send_message(message.author, "You have been given {} credits.".format(amount,))
send_message(client, message.author, "You have been given {} credits.".format(amount,))
else:
client.send_message(message.author, "You already have credits. Stop begging.")
send_message(client, message.author, "You already have credits. Stop begging.")
return
def do_grantcredits(client, message_parts, message, channel=None):
if not channel and message.author.id != '78767557628133376':
client.send_message(message.channel, "You are not Hellsbreath. Use !gimmecredits to get a few extra if you run out.")
send_message(client, message.channel, "You are not Hellsbreath. Use !gimmecredits to get a few extra if you run out.")
return
members = data.db_get_all_members()
if len(members) < 0:
client.send_message(message.channel, "There was a problem looking up your information.")
send_message(client, message.channel, "There was a problem looking up your information.")
else:
for member in members:
credits = data.db_get_credit(member['member_id'])
if credits < 100:
data.db_update_credit(member['member_id'], 100)
if channel:
client.send_message(channel, "{} has been given {} credits.".format(member['member_name'], 100))
send_message(client, channel, "{} has been given {} credits.".format(member['member_name'], 100))
else:
client.send_message(message.channel, "{} has been given {} credits.".format(member['member_name'], 100))
send_message(client, message.channel, "{} has been given {} credits.".format(member['member_name'], 100))
return
def do_ticketrank(client, message_parts, message):
members = data.db_get_all_members()
if len(members) < 0:
client.send_message(message.channel, "There was a problem looking up your information.")
send_message(client, message.channel, "There was a problem looking up your information.")
else:
ticket_count = 0
for member in members:
if member['discord_id'] != '78767557628133376':
ticket_count += member['tickets']
if ticket_count == 0:
client.send_message(message.channel, "No Tickets have been sold for this raffle.")
send_message(client, message.channel, "No Tickets have been sold for this raffle.")
return
out_string = ""
......@@ -456,24 +438,24 @@ def do_ticketrank(client, message_parts, message):
percent = (float(member['tickets']) / float(ticket_count)) * 100.0
out_string += "{} - {}%\n".format(byteify(member['member_name']), int(percent))
client.send_message(message.channel, out_string)
send_message(client, message.channel, out_string)
return
def do_startraffle(client, message_parts, message):
if message.author.id != '78767557628133376':
client.send_message(message.channel, "You are not Hellsbreath. Go die in an especially hot fire.")
send_message(client, message.channel, "You are not Hellsbreath. Go die in an especially hot fire.")
return
members = data.db_get_all_members()
if len(members) < 0:
client.send_message(message.channel, "There was a problem looking up your information.")
send_message(client, message.channel, "There was a problem looking up your information.")
else:
ticket_count = 0
for member in members:
if member['discord_id'] != '78767557628133376':
ticket_count += member['tickets']
if ticket_count == 0:
client.send_message(message.channel, "No Tickets have been sold for this raffle.")
send_message(client, message.channel, "No Tickets have been sold for this raffle.")
return
out_string = "The final standings are as follows: \n\n"
......@@ -502,24 +484,25 @@ def do_startraffle(client, message_parts, message):
winner = random.choice(ticket_reel)
while winner in ticket_reel:
ticket_reel.remove(winner)
client.send_message(message.channel, "\n\n\n**The winner is....\n\n{}!**".format(byteify(winner)))
send_message(client, message.channel, "\n\n\n**The winner is....\n\n{}!**".format(byteify(winner)))
if len(ticket_reel) > 0:
second = random.choice(ticket_reel)
while second in ticket_reel:
ticket_reel.remove(second)
time.sleep(0.5)
client.send_message(message.channel, "\n\n*2nd Place:* {}".format(byteify(second)))
send_message(client, message.channel, "\n\n*2nd Place:* {}".format(byteify(second)))
if len(ticket_reel) > 0:
third = random.choice(ticket_reel)
time.sleep(0.5)
client.send_message(message.channel, "\n*3rd Place:* {}".format(byteify(third)))
send_message(client, message.channel, "\n*3rd Place:* {}".format(byteify(third)))
for member in client.get_all_members():
log(member.id)
if member.id == '78767557628133376':
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])
log(priv_message)
client.send_message(member, priv_message)
send_message(client, member, priv_message)
break
return
......@@ -532,7 +515,7 @@ def do_pastraffle(client, message_parts, message):
for key, value in raffles.iteritems():
if value['current'] == 0:
out_str += "{} - {}\n".format(key, value['title'])
client.send_message(message.channel, "Past Raffles:\n\n{}".format(out_str))
send_message(client, message.channel, "Past Raffles:\n\n{}".format(out_str))
return
......@@ -550,7 +533,7 @@ def do_raffle(client, message_parts, message):
title = value['title']
description = value['description']
link = value['link']
client.send_message(message.channel, """Current Raffle Item:
send_message(client, message.channel, """Current Raffle Item:
**1st Place**
......@@ -574,7 +557,7 @@ You will be contacted if you win. To win you must purchase tickets with the !buy
You can get extra credits by playing !slots <amount> and !bet <amount> on BlackJack.
**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.*
""".format(title, description, link, date))
""".format(title, byteify(description), link, date))
return
......@@ -584,32 +567,32 @@ def do_buyticket(client, message_parts, message):
log("Member: {}".format(member,))
if not member:
log("there")
client.send_message(message.author, "There was a problem looking up your information.")
send_message(client, message.author, "There was a problem looking up your information.")
else:
log("here")
log("Buying Ticket for: {}".format(byteify(member['member_name'])))
result, response = data.db_buy_ticket(member['member_id'], 1)
log("Buy Result: {} - {}".format(result, response))
if not result:
client.send_message(message.author, response)
send_message(client, message.author, response)
return
credits = data.db_get_credit(member['member_id'])
client.send_message(message.author, "Raffle ticket purchased. Tickets: {} Credits: {}".format(response, credits))
send_message(client, message.author, "Raffle ticket purchased. Tickets: {} Credits: {}".format(response, credits))
return
def do_balance(client, message_parts, message):
member = data.db_get_member(message.author.id)
if not member:
client.send_message(message.author, "There was a problem looking up your information.")
send_message(client, message.author, "There was a problem looking up your information.")
else:
client.send_message(message.author, "Credits: {}\nTickets: {}".format(member['credits'], member['tickets']))
send_message(client, message.author, "Credits: {}\nTickets: {}".format(member['credits'], member['tickets']))
return
def do_slotsrules(client, message_parts, message):
client.send_message(message.channel, """Paying Combinations:
send_message(client, message.channel, """Paying Combinations:
:moneybag:\t:moneybag:\t:moneybag:\t\t\t pays\t250
:bell:\t:bell:\t:bell:/:moneybag:\tpays\t20
......@@ -632,20 +615,20 @@ To Play: !slots <bet>""")
def do_slots(client, message_parts, message):
member = data.db_get_member(message.author.id)
if not member:
client.send_message(message.author, "There was a problem looking up your information.")
send_message(client, message.author, "There was a problem looking up your information.")
return
elif type(message.channel) is not discord.channel.PrivateChannel:
client.send_message(message.author, "You must make all bets / gaming via private message.")
send_message(client, message.author, "You must make all bets / gaming via private message.")
return
bet_amount = message.content[7:]
log("Member: {} Slots Bet: {}".format(member['member_name'], bet_amount))
if not bet_amount.isdigit() or int(bet_amount) > 10 or int(bet_amount) < 0:
client.send_message(message.author, "Please provide a bet amount up to 10 credits.")
send_message(client, message.author, "Please provide a bet amount up to 10 credits.")
return
result, error_message = data.db_update_credit(member['member_id'], -int(bet_amount))
if not result:
client.send_message(message.author, error_message)
send_message(client, message.author, error_message)
return
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):
if winnings > 0:
result, error_message = data.db_update_credit(member['member_id'], winnings)
if not result:
client.send_message(message.author, error_message)
send_message(client, message.author, error_message)
return
credits = data.db_get_credit(member['member_id'])
out_string += "\nCredits: {}".format(credits)
client.send_message(message.author, out_string)
send_message(client, message.author, out_string)
return
def do_bj_hit(client, message_parts, message):
member = data.db_get_member(message.author.id)
if not member:
client.send_message(message.author, "There was a problem looking up your information.")
send_message(client, message.author, "There was a problem looking up your information.")
elif type(message.channel) is not discord.channel.PrivateChannel:
client.send_message(message.author, "You must make all bets / gaming via private message.")
send_message(client, message.author, "You must make all bets / gaming via private message.")
else:
state = data.db_get_minigame_state(member['member_id'], 'blackjack')
if state:
......@@ -724,25 +707,25 @@ def do_bj_hit(client, message_parts, message):
log("{} - {}".format(member['member_name'], response.format(win,)))
result, error_message = data.db_update_credit(member['member_id'], int(win))
if not result:
client.send_message(message.author, error_message)
send_message(client, message.author, error_message)
return
credits = data.db_get_credit(member['member_id'])
out_string += "\nCredits: {}".format(credits)
client.send_message(message.author, out_string)
send_message(client, message.author, out_string)
else:
client.send_message(message.author, "You must start a game with !bet before you can ask for a new card.")
send_message(client, message.author, "You must start a game with !bet before you can ask for a new card.")
return
def do_bj_stay(client, message_parts, message):
member = data.db_get_member(message.author.id)
if not member:
client.send_message(message.author, "There was a problem looking up your information.")
send_message(client, message.author, "There was a problem looking up your information.")
elif type(message.channel) is not discord.channel.PrivateChannel:
client.send_message(message.author, "You must make all bets / gaming via private message.")
send_message(client, message.author, "You must make all bets / gaming via private message.")
else:
state = data.db_get_minigame_state(member['member_id'], 'blackjack')
if state:
......@@ -756,24 +739,24 @@ def do_bj_stay(client, message_parts, message):
log("{} - {}".format(member['member_name'], response.format(win,)))
result, error_message = data.db_update_credit(member['member_id'], int(win))
if not result:
client.send_message(message.author, error_message)
send_message(client, message.author, error_message)
return
credits = data.db_get_credit(member['member_id'])
out_string += "\nCredits: {}".format(credits)
client.send_message(message.author, out_string)
send_message(client, message.author, out_string)
return
def do_bj_bet(client, message_parts, message):
member = data.db_get_member(message.author.id)
if not member:
client.send_message(message.author, "There was a problem looking up your information.")
send_message(client, message.author, "There was a problem looking up your information.")
elif type(message.channel) is not discord.channel.PrivateChannel:
client.send_message(message.author, "You must make all bets / gaming via private message.")
send_message(client, message.author, "You must make all bets / gaming via private message.")
else:
state = data.db_get_minigame_state(member['member_id'], 'blackjack')
if state:
client.send_message(message.author, "You are already playing a game!")
send_message(client, message.author, "You are already playing a game!")
out_string = ""
bj = pickle.loads(str(state))
......@@ -790,12 +773,12 @@ def do_bj_bet(client, message_parts, message):
log("{} - {}".format(member['member_name'], response.format(win,)))
result, error_message = data.db_update_credit(member['member_id'], int(win))
if not result:
client.send_message(message.author, error_message)
send_message(client, message.author, error_message)
return
credits = data.db_get_credit(member['member_id'])
out_string += "\nCredits: {}".format(credits)
client.send_message(message.author, out_string)
send_message(client, message.author, out_string)
return
......@@ -804,12 +787,12 @@ def do_bj_bet(client, message_parts, message):
log("Member: {} Bet: {}".format(member['member_name'], bet_amount))
if not bet_amount.isdigit():
client.send_message(message.author, "Please provide a bet amount. !bet 10")
send_message(client, message.author, "Please provide a bet amount. !bet 10")
return
result, error_message = data.db_update_credit(member['member_id'], -int(bet_amount))
if not result:
client.send_message(message.author, error_message)
send_message(client, message.author, error_message)
return
out_string += "Welcome to BlackJack! :flower_playing_cards: You have placed a bet of: {}\n".format(bet_amount)
bj = Blackjack(bet_amount)
......@@ -826,12 +809,12 @@ def do_bj_bet(client, message_parts, message):
log("{} - {}".format(member['member_name'], response.format(win,)))
result, error_message = data.db_update_credit(member['member_id'], int(win))
if not result:
client.send_message(message.author, error_message)
send_message(client, message.author, error_message)
return
credits = data.db_get_credit(member['member_id'])
out_string += "\nCredits: {}".format(credits)
client.send_message(message.author, out_string)
send_message(client, message.author, out_string)
return
......@@ -862,7 +845,7 @@ def do_msg(client, message_parts, message):
msg_datetime = tmp_date
msg_idx = 4
except ValueError:
client.send_message(channel, 'Your shitty message has been rejected {}. Next time learn how to date...MM\\DD\\YYYY'.format(message.author.mention()))
send_message(client, channel, 'Your shitty message has been rejected {}. Next time learn how to date...MM\\DD\\YYYY'.format(message.author.mention()))
return
username = message_bits[1]
......@@ -872,8 +855,9 @@ def do_msg(client, message_parts, message):
if username.lower() == member.name.lower():
user_mention = member.mention()
user_id = member.id
break
if user_mention == '':
client.send_message(channel, 'Your shitty message has been rejected {}. That user does not exist.'.format(message.author.name))
send_message(client, channel, 'Your shitty message has been rejected {}. That user does not exist.'.format(message.author.name))
return
msg_text = byteify(' '.join(message_bits[msg_idx:]))
......@@ -884,13 +868,13 @@ def do_msg(client, message_parts, message):
#test_ch = Object(channel.id)
#client.send_message(test_ch, 'Test Message {}.'.format(author))
except Exception as e:
client.send_message(channel, 'Your shitty message has been rejected {}. {}'.format(author.name, format_exception(e)))
send_message(client, channel, 'Your shitty message has been rejected {}. {}'.format(author.name, format_exception(e)))
return
if msg_datetime < datetime.datetime.now():
client.send_message(channel, '{} your message will be delivered to {} as soon as they are available.'.format(author.name, user_mention))
send_message(client, channel, '{} your message will be delivered to {} as soon as they are available.'.format(author.name, user_mention))
else:
client.send_message(channel, '{} your message will be delivered to {} {}.'.format(author.name, user_mention, human(msg_datetime)))
check_msg_queue()
send_message(client, channel, '{} your message will be delivered to {} {}.'.format(author.name, user_mention, human(msg_datetime)))
check_msg_queue(client)
return
......@@ -898,7 +882,7 @@ def do_addfortune(client, message_parts, message):
try:
fortune = message.content[9:]
if 'aa737a5846' in fortune:
client.send_message(message.channel, '{} you stop it, you are a pedofile, stop looking at little girls.'.format(message.author.mention()))
send_message(client, message.channel, '{} you stop it, you are a pedofile, stop looking at little girls.'.format(message.author.mention()))
return
date_added = datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S')
c = conn.cursor()
......@@ -907,9 +891,9 @@ def do_addfortune(client, message_parts, message):
log("Added fortune")
except Exception as e:
log(e.message)
client.send_message(message.channel, 'Your shitty fortune has been rejected {}.'.format(message.author.mention()))
send_message(client, message.channel, 'Your shitty fortune has been rejected {}.'.format(message.author.mention()))
return
client.send_message(message.channel, 'Your shitty fortune has been added {}.'.format(message.author.mention()))
send_message(client, message.channel, 'Your shitty fortune has been added {}.'.format(message.author.mention()))
return
......@@ -924,16 +908,16 @@ def do_fortune(client, message_parts, message):
log(e)
pass
if not fortune:
client.send_message(message.channel, 'Try adding a fortune with "!addfortune <fortune>" {}!'.format(message.author.mention()))
send_message(client, message.channel, 'Try adding a fortune with "!addfortune <fortune>" {}!'.format(message.author.mention()))
else:
client.send_message(message.channel, '{} Your fortune is... {}'.format(message.author.mention(), byteify(fortune)))
send_message(client, message.channel, '{} Your fortune is... {}'.format(message.author.mention(), byteify(fortune)))
return
def do_question(client, message_parts, message):
question = message.content[10:]
if "is it gay" in question:
client.send_message(message.channel, 'Yes {}, it is gay.'.format(message.author.mention()))
send_message(client, message.channel, 'Yes {}, it is gay.'.format(message.author.mention()))
return
res = wolf.query(question)
try:
......@@ -942,7 +926,7 @@ def do_question(client, message_parts, message):
for pod in res.pods:
if pod.text:
pod_text.append(pod.text)
client.send_message(message.channel, '{} {}.'.format(message.author.mention(), byteify("\n".join(pod_text)[:1990])))
send_message(client, message.channel, '{} {}.'.format(message.author.mention(), byteify("\n".join(pod_text)[:1990])))
else:
tagged_sent = pos_tag(question.replace('?', '').split())
proper_nouns = [word for word, pos in tagged_sent if pos == 'NNP']
......@@ -950,13 +934,13 @@ def do_question(client, message_parts, message):
if wiki_search.strip() != "":
log("Looking up {}".format(wiki_search))
wiki_out = wikipedia.summary(wiki_search, sentences=3)
client.send_message(message.channel, '{} {}.'.format(message.author.mention(), byteify(wiki_out)))
send_message(client, message.channel, '{} {}.'.format(message.author.mention(), byteify(wiki_out)))
else:
client.send_message(message.channel, 'I don\'t know {}.'.format(message.author.mention()))
send_message(client, message.channel, 'I don\'t know {}.'.format(message.author.mention()))
return
except Exception as e:
log(format_exception(e))
client.send_message(message.channel, 'I don\'t know {}.'.format(message.author.mention()))
send_message(client, message.channel, 'I don\'t know {}.'.format(message.author.mention()))
return
......@@ -964,7 +948,7 @@ def do_addjoke(client, message_parts, message):
try:
joke = message.content[9:]
if 'aa737a5846' in joke:
client.send_message(message.channel, '{} you stop it, you are a pedofile, stop looking at little girls.'.format(message.author.mention()))
send_message(client, message.channel, '{} you stop it, you are a pedofile, stop looking at little girls.'.format(message.author.mention()))
return
c = conn.cursor()
c.execute("INSERT INTO jokes (joke) VALUES (?)", (joke,))
......@@ -972,9 +956,9 @@ def do_addjoke(client, message_parts, message):
log("Added joke")
except Exception as e:
log(e.message)
client.send_message(message.channel, 'Your shitty joke has been rejected {}.'.format(message.author.mention()))
send_message(client, message.channel, 'Your shitty joke has been rejected {}.'.format(message.author.mention()))
return
client.send_message(message.channel, 'Your shitty joke has been added {}.'.format(message.author.mention()))
send_message(client, message.channel, 'Your shitty joke has been added {}.'.format(message.author.mention()))
return
......@@ -988,40 +972,40 @@ def do_joke(client, message_parts, message):
log(e)
pass
if not joke:
client.send_message(message.channel, 'Try adding a joke with "!addjoke <joke>" {}!'.format(message.author.mention()))
send_message(client, message.channel, 'Try adding a joke with "!addjoke <joke>" {}!'.format(message.author.mention()))
else:
client.send_message(message.channel, '{} {}'.format(message.author.mention(), byteify(joke)))
send_message(client, message.channel, '{} {}'.format(message.author.mention(), byteify(joke)))
return
def do_secret(client, message_parts, message):
client.send_message(message.channel, 'git gud {}! My source is here: http://git.savsoul.com/barry/discordbot\nVersion: {}'.format(message.author.mention(), VERSION))
send_message(client, message.channel, 'git gud {}! My source is here: http://git.savsoul.com/barry/discordbot\nVersion: {}'.format(message.author.mention(), VERSION))
return
def do_waifu(client, message_parts, message):
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()))
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()))
return
def do_hillary(client, message_parts, message):
client.send_message(message.channel, ':bomb: Ohhhhhh, now you done it...:bomb:'.format(message.author.mention()))
send_message(client, message.channel, ':bomb: Ohhhhhh, now you done it...:bomb:'.format(message.author.mention()))
return
def do_squid(client, message_parts, message):
client.send_message(message.channel, 'くコ:彡 くコ:彡 くコ:彡 くコ:彡')
send_message(client, message.channel, 'くコ:彡 くコ:彡 くコ:彡 くコ:彡')
return
def do_stars(client, message_parts, message):
client.send_message(message.channel, '✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈ ✰═━┈┈ ✰═━┈┈')
send_message(client, message.channel, '✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈  ✮═━┈  ✰═━┈ ✰═━┈┈ ✰═━┈┈')
return
def do_rigged(client, message_parts, message):
lines = open('studylyrics.txt').read().splitlines()
client.send_message(message.channel, ":musical_note: {} :musical_note:".format(random.choice(lines)))
send_message(client, message.channel, ":musical_note: {} :musical_note:".format(random.choice(lines)))
return
def start_timer(client):
......@@ -1036,17 +1020,42 @@ def start_timer(client):
do_grantcredits(client, None, None, channel)
needs_loot = False
time.sleep(10000)
log('Sleeping')
#log('Sleeping')
def thread_exception_handler(method, client, message_parts, message):
try:
if message:
globals()[method](client, message_parts[1:], message)
globals()[method](client, message_parts, message)
else:
globals()[method](client)
except Exception as e:
log("{} - {}".format(format_exception(e), e.message))
#################
# Client Events
#################
@client.event
def on_socket_raw_send(payload, binary=False):
check_msg_queue(client)
@client.event
def on_status(member):
for member in client.get_all_members():
try:
db_member = data.db_get_member(member.id)
if not db_member:
log("Creating new member: {}".format(member))
data.db_create_member(member)
else:
data.db_update_member(member, db_member)
check_msg_queue(client)
except Exception as e:
log("Exception: {}".format(format_exception(e)))
pass
@client.event
def on_message(message):
#print message.content
......@@ -1070,7 +1079,7 @@ def on_message(message):
log('Someone is talking to %s' % (client.user.name.lower(),))
if ' or ' in message.content:
questions = message.content[len(client.user.name)+1:].replace('?', '').split(' or ')
client.send_message(message.channel, '{} I choose: {}'.format(message.author.mention(), random.choice(questions).encode('utf-8', errors='ignore')))
send_message(client, message.channel, '{} I choose: {}'.format(message.author.mention(), random.choice(questions).encode('utf-8', errors='ignore')))
@client.event
......@@ -1081,11 +1090,12 @@ def on_ready():
log('------')
for member in client.get_all_members():
if member.id == '78767557628133376':
client.send_message(member, "Bot Started")
send_message(client, member, "Bot Started")
break
# for channel in client.get_all_channels():
# client.send_message(member, "Bot Started {} {}".format(channel.id, channel.name))
check_msg_queue()
check_msg_queue(client)
thread.start_new_thread(thread_exception_handler, ('start_timer', client, None, None))
......
import random
import time
import pickle
import math
FIND_PERCENTAGE = 100
SKILL_PERCENT = 80
......@@ -15,8 +16,41 @@ class HuntResponse:
self.message = message
self.monster = monster
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]
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]
exp_table = {
15: 600,
14: 600,
13: 600,
12: 600,
11: 600,
10: 600,
9: 600,
8: 600,
7: 550,
6: 450,
5: 350,
4: 300,
3: 240,
2: 220,
1: 210,
0: 200,
-1: 180,
-2: 160,
-3: 150,
-4: 140,
-5: 130,
-6: 120,
-7: 110,
-8: 100,
-9: 80,
-10: 60,
-11: 40,
-12: 40,
-13: 40,
-14: 40,
-15: 40,
}
class Jobs:
WAR = 1
MNK = 2
......@@ -85,6 +119,12 @@ Families = {
'charmable': False,
'aspir': False,
'drain': False,
'base_vit': 10,
'vit_per_level': 0.9334,
'base_str': 9,
'str_per_level': 0.8934,
'base_agi': 7,
'agi_per_level': 0.76,
'temperament_attitude': {
'initial_value': 4,
'actions': {
......@@ -116,6 +156,12 @@ Families = {
'charmable': False,
'aspir': True,
'drain': True,
'base_vit': 8,
'vit_per_level': 0.8,
'base_str': 8,
'str_per_level': 0.8534,
'base_agi': 9,
'agi_per_level': 0.88,
'temperament_attitude': {
'initial_value': 4,
'actions': {
......@@ -141,12 +187,16 @@ Monsters = {
'Mechanical Menace': {
'initial_level': 9,
'family': 'acrolith',
'zone': 'Abyssea - Uleguerand'
'zone': 'Abyssea - Uleguerand',
'hp': 1000,
'weapon_base_damage': 40
},
'Floating Eye': {
'initial_level': 3,
'family': 'ahriman',
'zone': 'Ranguemont Pass'
'zone': 'Ranguemont Pass',
'hp': 1000,
'weapon_base_damage': 120
}
}
......@@ -156,7 +206,7 @@ class Pankration:
pass
def start_battle(self, monster1, monster2, battle_type):
battle = Battle(monster1, monster2, battle_type)
battle = Arena(monster1, monster2, battle_type)
battle.start()
return battle
......@@ -176,8 +226,11 @@ class Pankration:
def hunt_monster(self, zone):
if random.randint(1, 100) < FIND_PERCENTAGE:
monster_data = Monsters[random.choice(self.get_monsters(zone))]
print(monster_data)
monster_name = random.choice(self.get_monsters(zone))
monster_data = Monsters[monster_name]
hp = monster_data['hp']
weapon_base_damage = monster_data['weapon_base_damage']
print("Monster: {} Data: {}".format(monster_name, monster_data))
family_name = monster_data['family']
level = monster_data['initial_level']
family = Families[family_name]
......@@ -193,7 +246,7 @@ class Pankration:
feral_skills.append(skills[2])
dicipline_level = 1
monster = Monster(family, level, main_job, support_job, feral_skills,
monster = Monster(monster_name, family, hp, level, weapon_base_damage, main_job, support_job, feral_skills,
[], dicipline_level)
return HuntResponse(HuntResponse.SUCCESS, "You captured the monster!",
monster)
......@@ -206,9 +259,12 @@ class Pankration:
class Monster:
def __init__(self, family, level, main_job, support_job, innate_feral_skills,
def __init__(self, monster_type, family, hp, level, weapon_base_damage, main_job, support_job, innate_feral_skills,
equipped_feral_skills, dicipline_level):
self.monster_type = monster_type
self.family = family
self.max_hp = hp
self.hp = hp
self.level = level
self.main_job = main_job
self.support_job = support_job
......@@ -220,8 +276,14 @@ class Monster:
self.pre_fight_command = {"temperament_posture": None, "temperament_attitude": None}
self.exp = exp_to_level[level] + 1
# TODO: Setup something more interesting for each monster.
self.weapon_base_damage = 43
self.weapon_base_damage = weapon_base_damage
self.ammo_damage = 0
self.base_vit = family['base_vit']
self.vit_per_level = family['vit_per_level']
self.base_str = family['base_str']
self.str_per_level = family['str_per_level']
self.base_agi = family['base_agi']
self.agi_per_level = family['agi_per_level']
def __str__(self):
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:
def add_xp(self, exp_to_add):
self.exp += exp_to_add
for i in range(self.level, 50):
for i in range(self.level, 51):
if self.exp > exp_to_level[i]:
if i > self.level:
# We leveled up!
print("Start level: {} New Level: {}".format(self.level, i))
self.level = i
#print("Start level: {} New Level: {}".format(self.level, i))
else:
print("Just another brick in the wall...")
pass#print("Just another brick in the wall...")
else:
break
# calc level based on xp
......@@ -260,9 +323,25 @@ class Monster:
else:
return "Obedient"
def get_vitality(self):
return int(round(max(self.base_vit, self.level * self.vit_per_level)))
def get_strength(self):
return int(round(max(self.base_str, self.level * self.str_per_level)))
def get_agility(self):
return int(round(max(self.base_agi, self.level * self.agi_per_level)))
def get_base_defense(self):
return (math.floor(self.get_vitality()/2) + 8 + self.level)
def get_hp_percent(self):
return max(0, int(round((self.hp/self.max_hp)*100)))
# Calculate the base damage against the provided defense
# attack_type can be 'ranged' or 'melee'
def get_physical_base_damage(self, defense, attack_type, level_difference):
#print("Defense: {} Type: {} Level diff: {}".format(defense, attack_type, level_difference))
# Calculate the attack/defense ratio
bd = float(self.weapon_base_damage)
if attack_type == 'ranged':
......@@ -285,8 +364,12 @@ class Monster:
cRatio = ratio - 0.050 * level_difference
if cRatio < 0:
cRatio = 0
if attack_type == 'ranged':
if cRatio > 3.0:
cRatio = 3.0
else:
if cRatio > 2.25:
cRatio = 2.25
# Calculate the pDif max as the max of our RNG
if cRatio <= 0.5:
pDif_max = 1+(10/9)*(cRatio-0.5)
......@@ -305,13 +388,21 @@ class Monster:
elif 1.5 <= cRatio <= cap:
pDif_min = 1+(10/9)*(cRatio-1.5)
print(pDif_min)
# Some fuckery since python doesn't let you do a rand between decimals
pDif_rand = float(random.randint(int(pDif_min*100000), int(pDif_max*100000))) / 100000.0
final_damage = bd * (pDif_rand * cRatio)
return final_damage
def attack(self, monster):
phy_damage = self.get_physical_base_damage(monster.get_base_defense(), 'melee', monster.level - self.level)
return (phy_damage, 'hits')
def apply_damage(self, damage):
self.hp -= damage
# Check life and return 'awesome', 'fucked up', 'dead' or something
# This should ONLY be executed at the start of battle.
def set_strategy(self, temperament_posture, temperament_attitude):
distance_from_nature = abs(self.temperament_posture - temperament_posture)
......@@ -333,19 +424,64 @@ class Monster:
#if severe request then reduce dicipline_level
pass
class Action:
def __init__(self, monster):
self.monster = monster
class AttackAction(Action):
def __init__(self, attacker, target, damage, message):
self.attacker = attacker
self.target = target
self.damage = damage
self.message = message
class DefeatAction(Action):
def __init__(self, attacker, target, message, xp):
self.attacker = attacker
self.target = target
self.message = message
self.xp = xp
class Arena:
class Battle:
def __init__(self, monster1, monster2, battle_type):
self.monster1 = monster1
self.monster2 = monster2
self.battle_type = battle_type
def perform_attack():
base_damage = get_physical_base_damage(monster2.defense, 'melee', 0)
def heal_monsters(self):
pass
def start(self):
self.heal_monsters()
self.m1_init = self.monster1.get_agility() + random.randint(1, 20)
self.m2_init = self.monster2.get_agility() + random.randint(1, 20)
def step(self):
actions = []
if self.m1_init > self.m2_init:
primary = self.monster1
secondary = self.monster2
else:
primary = self.monster2
secondary = self.monster1
result1 = primary.attack(secondary)
secondary.apply_damage(result1[0])
actions.append(AttackAction(primary, secondary, result1[0], result1[1]))
if secondary.hp <= 0:
xp = 200 + (20 * (primary.level - secondary.level))
actions.append(DefeatAction(secondary, primary, 'was defeated', xp))
return actions
result2 = secondary.attack(primary)
primary.apply_damage(result2[0])
actions.append(AttackAction(secondary, primary, result2[0], result2[1]))
if primary.hp <= 0:
xp = 200 + (20 * (secondary.level - primary.level))
actions.append(DefeatAction(primary, secondary, 'was defeated', xp))
return actions
return actions
class Arena:
pass
#print Families
......@@ -360,26 +496,46 @@ time.sleep(0.5)
if hunt_response.result == HuntResponse.SUCCESS:
print(hunt_response.message)
monster = hunt_response.monster
print("The Soul Plate Shows: \n\n{}".format(monster))
print(monster.set_strategy(4, 3))
print(monster.set_strategy(1, 1))
print(monster.set_strategy(1, 2))
monster.add_xp(2900)
phy_damage = monster.get_physical_base_damage(100, 'melee', -15)
print("Phys Attack: {}".format(phy_damage))
# print("The Soul Plate Shows: \n\n{}".format(monster))
# print(monster.set_strategy(4, 3))
# print(monster.set_strategy(1, 1))
# print(monster.set_strategy(1, 2))
#monster.add_xp(22900)
# phy_damage = monster.get_physical_base_damage(100, 'melee', -15)
# print("Phys Attack: {}".format(phy_damage))
# print(monster.get_base_defense())
# monster.add_xp(22900)
# print(monster.get_base_defense())
# monster.add_xp(222900)
# print(monster.get_base_defense())
else:
print(hunt_response.message)
hunt_zone = p.list_zones()[1]
hunt_response = p.hunt_monster(hunt_zone)
if hunt_response.result == HuntResponse.SUCCESS:
monster2 = hunt_response.monster
monster2.add_xp(16900)
phy_damage = monster2.attack(monster)
print("Phys Attack: {}".format(phy_damage))
battle_arena = p.start_battle(monster, monster2, "derp")
fighting = True
while fighting:
actions = battle_arena.step()
time.sleep(2)
for action in actions:
if isinstance(action, AttackAction):
print("{} {} {} for {}.".format(action.attacker.monster_type, action.message, action.target.monster_type, action.damage))
if isinstance(action, DefeatAction):
print("{} {}. {} gains {} xp.".format(action.target.monster_type, action.message, action.attacker.monster_type, action.xp))
fighting = False
break
print("\n{} {}% - {} {}%\n".format(monster.monster_type, monster.get_hp_percent(), monster2.monster_type, monster2.get_hp_percent()))
......