Advertisement
Guest User

yoyo bot

a guest
May 26th, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 182.64 KB | None | 0 0
  1. from os import listdir
  2. from os.path import isfile, join
  3.  
  4. import asyncio
  5. import discord
  6. import math
  7. import os
  8. import random
  9. import requests
  10. import setup
  11. import time
  12.  
  13. from pluglib import *
  14.  
  15. global plugin_manager
  16. def load_plugins():
  17.     global plugin_manager
  18.     plugin_manager = PluginManager(client)
  19.  
  20.     onlyfiles = [f for f in listdir("plugins/") if isfile(join("plugins/", f))]
  21.     loaded = 0
  22.     for filename in onlyfiles:
  23.         fname = filename[:-3]
  24.         if "__init__" not in filename and ".py" in filename and not plugin_disabled(fname):
  25.             print("importing " + filename + "...")
  26.             try:
  27.                 test = __import__("plugins."+fname, fromlist=["plugins"])
  28.                 test.setup(plugin_manager, fname)
  29.                 loaded += 1
  30.             except():
  31.                 print("ERROR: Failed to import " + filename)
  32.     print("Done, loaded " + str(loaded) + " plugins!")
  33.  
  34. client = discord.Client()
  35. client.voice = None
  36.  
  37. global poke_cooldowns, uptime_cooldown, uptime_start, left_messages, hangman_word, hangman_found, hangman_words, hangman_guessed_letters, hangman_tries
  38. global activity, activity_events, activity_cds, activity_triggers, yoyo_code_link, command_binds, custom_commands, settings, plugin_disables
  39. global permissions, command_swaps, user_roles, money_shop, user_money, ball_8, rewards
  40. global msg_history, tag_stats, nickname, nick_players, songs, collections, tagged, old_tagged, radio_channel, current_music_player
  41. global voice_chn, song_list, song_collection, song_finished, recent_songs, skip_votes, song_queue, song_paused, nicknames, hangman_guess, song_volume
  42.  
  43. def setup_variables():
  44.     global poke_cooldowns, uptime_cooldown, uptime_start, left_messages, hangman_word, hangman_found, hangman_words, hangman_guessed_letters, hangman_tries
  45.     global activity, activity_events, activity_cds, activity_triggers, yoyo_code_link, command_binds, custom_commands, settings, plugin_disables
  46.     global permissions, command_swaps, user_roles, money_shop, user_money, ball_8, rewards
  47.     global msg_history, tag_stats, nickname, nick_players, songs, collections, tagged, old_tagged, radio_channel, current_music_player
  48.     global voice_chn, song_list, song_collection, song_finished, recent_songs, skip_votes, song_queue, song_paused, nicknames, hangman_guess, song_volume
  49.     poke_cooldowns = {}
  50.     uptime_cooldown = 0
  51.     uptime_start = None
  52.  
  53.     left_messages = {}
  54.  
  55.     hangman_word = ""
  56.     hangman_found = ""
  57.     hangman_guess = 0
  58.     hangman_guessed_letters = ""
  59.     hangman_tries = 0
  60.  
  61.     hangman_words = []
  62.  
  63.     activity = {}
  64.     activity_events = {}
  65.     activity_cds = {}
  66.     activity_triggers = {}
  67.  
  68.     yoyo_code_link = "http://pastebin.com/2PZARLXu"
  69.  
  70.     command_binds = {}
  71.     custom_commands = {}
  72.  
  73.     plugin_disables = {}
  74.  
  75.     settings = {}
  76.  
  77.     permissions = {}
  78.     command_swaps = {
  79.         "radio": "song",
  80.         "hangman": "hman",
  81.         "coin": "flip",
  82.         "dice": "roll",
  83.         "die": "roll",
  84.         "c&h": "cah",
  85.         "humble": "hb",
  86.         "humblebundle": "hb"
  87.     }
  88.  
  89.     user_roles = {}
  90.  
  91.     money_shop = {}
  92.  
  93.     ball_8 = [
  94.         "It is certain",
  95.         "It is decidedly so",
  96.         "Without a doubt",
  97.         "Yes, definitely",
  98.         "You may rely on it",
  99.         "As I see it, yes",
  100.         "Most likely",
  101.         "Outlook good",
  102.         "Yes",
  103.         "Signs point to yes",
  104.         "Reply hazy try again",
  105.         "Ask again later",
  106.         "Better not tell you now",
  107.         "Cannot predict now",
  108.         "Concentrate and ask again",
  109.         "Don't count on it",
  110.         "My reply is no",
  111.         "My sources say no",
  112.         "Outlook not so good",
  113.         "Very doubtful"
  114.     ]
  115.  
  116.     user_money = {}
  117.  
  118.     rewards = {}
  119.  
  120.     msg_history = [""] * 10
  121.  
  122.     tag_stats = {}
  123.  
  124.     nicknames = {}
  125.     nick_players = []
  126.     songs = {}
  127.     collections = []
  128.  
  129.     tagged = ""
  130.     old_tagged = ""
  131.  
  132.     radio_channel = None
  133.     current_music_player = None
  134.     voice_chn = None
  135.     song_list = []
  136.     song_collection = None
  137.     song_finished = False
  138.     recent_songs = []
  139.     skip_votes = []
  140.     song_queue = []
  141.     song_paused = True
  142.     song_volume = 1
  143.  
  144. def load_plugin_disables():
  145.     f = open("data/plugin_disables.txt", "r")
  146.     for line in f:
  147.         dat = line.replace("\n", "").split("/+++/")
  148.         plugin_disables[dat[0]] = (dat[1].lower() == "true")
  149.     f.close()
  150.  
  151. def save_plugin_disables():
  152.     f = open("data/plugin_disables.txt", "w")
  153.     for plugin_name in plugin_disables:
  154.         f.write(plugin_name + "/+++/" + str(plugin_disables[plugin_name]) + "\n")
  155.     f.close()
  156.  
  157. def plugin_disabled(plugin_name):
  158.     if plugin_name in plugin_disables:
  159.         return plugin_disables[plugin_name]
  160.     return False
  161.  
  162. def load_custom_commands():
  163.     f = open("data/custom_commands.txt", "r")
  164.     for line in f:
  165.         dat = line.replace("\n", "").split("/+++/")
  166.         if dat[0] != "":
  167.             custom_commands[dat[0]] = dat[1]
  168.     f.close()
  169.  
  170. def save_custom_commands():
  171.     f = open("data/custom_commands.txt", "w")
  172.     for cmd in custom_commands:
  173.         f.write(cmd + "/+++/" + custom_commands[cmd] + "\n")
  174.     f.close()
  175.  
  176.  
  177. #max_help_lines - the amount of lines shown in a help page
  178. def mxlns():
  179.     if "max_help_lines" in settings:
  180.         return int(settings["max_help_lines"])
  181.     return 5
  182.  
  183. #bot_name - the name of the bot in your channel
  184. def botname():
  185.     if "bot_name" in settings:
  186.         return settings["bot_name"]
  187.     return "yoyobot"
  188.  
  189. #command prefix - what signifies a message is a command
  190. def cfix():
  191.     if "command_prefix" in settings:
  192.         return settings["command_prefix"]
  193.     return "!"
  194.  
  195. #radio channel - the name of the channel to dump the radio links in
  196. def rchn():
  197.     if "radio_channel" in settings:
  198.         return settings["radio_channel"]
  199.     return "radio_channel"
  200.  
  201. #radio update rate - the rate at which you check if a song has finished (integer in seconds)
  202. def ruprt():
  203.     if "radio_update_rate" in settings:
  204.         return int(settings["radio_update_rate"])
  205.     return 3
  206.  
  207. #repeat cap - how many recent songs the radio tries to avoid
  208. def rpcap():
  209.     if "repeat_cap" in settings:
  210.         return int(settings["repeat_cap"])
  211.     return 10
  212.  
  213. #tag limit - the limit on the size of a message with someones tag in it
  214. def taglimit():
  215.     if "tag_limit" in settings:
  216.         return int(settings["tag_limit"])
  217.     return 300
  218.  
  219.  
  220.  
  221. def welcome(member):
  222.     if get_role(member.name) is None:
  223.         set_role(member.name, "DEFAULT")
  224.         if "welcome_message" in settings:
  225.             msg = settings["welcome_message"]
  226.             if msg != "":
  227.                 msg.replace("%name%", member.name).replace("%c%", cfix())
  228.                 client.send_message(member, msg)
  229.  
  230. def load_settings():
  231.     f = open("data/settings.txt", "r")
  232.     for line in f:
  233.         dat = line.replace("\n", "").split("=")
  234.         if dat[0] != "":
  235.             settings[dat[0]] = "=".join(dat[1:])
  236.     f.close()
  237.  
  238. def save_settings():
  239.     f = open("data/settings.txt", "w")
  240.     for setting in settings:
  241.         f.write(setting + "=" + settings[setting] + "\n")
  242.     f.close()
  243.  
  244. def save_binds():
  245.     f = open("data/bind.txt", "w")
  246.     for basename in command_binds.keys():
  247.         f.write(basename + "/+++/" + "/+++/".join(command_binds[basename]) + "\n")
  248.     f.close()
  249.  
  250. def load_binds():
  251.     f = open("data/bind.txt", "r")
  252.     for line in f:
  253.         dat = line.replace("\n", "").split("/+++/")
  254.         if dat[0] != "":
  255.             command_binds[dat[0]] = dat[1:]
  256.     f.close()
  257.  
  258. def set_bind(basename, bind):
  259.     command_binds[basename] = [bind]
  260.     save_binds()
  261.  
  262. def add_bind(basename, bind):
  263.     if basename not in command_binds:
  264.         set_bind(basename, bind)
  265.     else:
  266.         command_binds[basename].append(bind)
  267.         save_binds()
  268.  
  269. def remove_bind(basename, bind):
  270.     if basename in command_binds:
  271.         if bind in command_binds[basename]:
  272.             command_binds[basename].remove(bind)
  273.             return True
  274.     return False
  275.  
  276. def get_binds(basename):
  277.     if basename in command_binds:
  278.         return ", ".join(command_binds[basename])
  279.     return None
  280.  
  281. def is_command(msg, basename):
  282.     if basename not in command_binds:
  283.         set_bind(basename, basename)
  284.     for bind in command_binds[basename]:
  285.         cmdstr = cfix() + bind
  286.         if msg.startswith(cmdstr + " ") or msg == cmdstr:
  287.             return True
  288.     return False
  289.  
  290. def load_hangman_words():
  291.     global hangman_words
  292.     f = open("hangman.txt", "r")
  293.     for line in f:
  294.         line = line.replace("\n", "").replace("\t", "")
  295.         if len(line) > 3:
  296.             if line[0] == line[0].lower():
  297.                 line = line.lower()
  298.                 hangman_words.append(line)
  299.     f.close()
  300.  
  301.  
  302. class Role:
  303.     def __init__(self, name, all, whitelist, blacklist, inher = []):
  304.         self.name = name
  305.         self.all = all
  306.         self.whitelist = whitelist
  307.         self.blacklist = blacklist
  308.         self.inheritence = inher
  309.  
  310.     def update_inhers(self, roles):
  311.         new_inheritence = []
  312.         for rolename in self.inheritence:
  313.             if rolename in roles:
  314.                 new_inheritence.append(roles[rolename])
  315.         self.inheritence = new_inheritence
  316.  
  317.     def check_inher(self, command, command_root):
  318.         for role in self.inheritence:
  319.             if role.check(command, command_root):
  320.                 return True
  321.         return False
  322.  
  323.     def check(self, command, command_root = ""):
  324.         #print(self.name + " : " + str(self.all) + " : " + str(self.whitelist) + " : " + str(self.blacklist) + " : " + command + " : " + command_root)
  325.         if self.all:
  326.             if not command in self.blacklist and not command_root in self.blacklist or self.check_inher(command, command_root):
  327.                 return True
  328.             return False
  329.         else:
  330.             if command in self.whitelist or (command_root in self.whitelist and command not in self.blacklist) or self.check_inher(command, command_root):
  331.                 return True
  332.             return False
  333.  
  334.     def get_all_str(self):
  335.         if self.all:
  336.             return "+all"
  337.         return "-all"
  338.  
  339.     def get_whitelist_str(self):
  340.         line = ""
  341.         for cmd in self.whitelist:
  342.             line = line + ",+" + cmd
  343.         return line
  344.  
  345.     def get_blacklist_str(self):
  346.         line = ""
  347.         for cmd in self.blacklist:
  348.             line = line + ",-" + cmd
  349.         return line
  350.  
  351.     def get_str(self):
  352.         return self.get_all_str() + self.get_whitelist_str() + self.get_blacklist_str()
  353.  
  354.  
  355.  
  356.  
  357. def load_permissions():
  358.     f = open("data/permissions.txt", "r")
  359.     for line in f:
  360.         spl = line.replace("\n", "").split("=")
  361.         rolename = spl[0]
  362.         tabs = spl[1].split(",")
  363.         role = Role(rolename, False, [], [])
  364.         for tab in tabs:
  365.             prefix = tab[0]
  366.             cmd = tab[1:]
  367.             if cmd in command_swaps:
  368.                 cmd = command_swaps[cmd]
  369.             if prefix == "*":
  370.                 role.inheritence.append(cmd)
  371.             else:
  372.                 if cmd == "all":
  373.                     if prefix == "+":
  374.                         role.all = True
  375.                     elif prefix == "-":
  376.                         role.all = False
  377.                 else:
  378.                     if prefix == "+":
  379.                         role.whitelist.append(cmd)
  380.                     elif prefix == "-":
  381.                         role.blacklist.append(cmd)
  382.         permissions[rolename] = role
  383.     f.close()
  384.     for rolename in permissions.keys():
  385.         permissions[rolename].update_inhers(permissions)
  386.  
  387. def save_permissions():
  388.     f = open("data/permissions.txt", "w")
  389.     for rolename in permissions.keys():
  390.         role = permissions[rolename]
  391.         line = rolename + "=" + role.get_str()
  392.         f.write(line + "\n")
  393.     f.close()
  394.  
  395. def create_permissions(rolename):
  396.     if rolename not in permissions:
  397.         permissions[rolename] = Role(rolename, False, [], [])
  398.         save_permissions()
  399.         return True
  400.     return False
  401.  
  402. def change_permissions(rolename, changes):
  403.     if rolename in permissions:
  404.         role = permissions[rolename]
  405.         for change in changes:
  406.             prefix = change[0]
  407.             cmd = change[1:]
  408.             if cmd in command_swaps:
  409.                 cmd = command_swaps[cmd]
  410.             if cmd == "all":
  411.                 if prefix == "+":
  412.                     role.all = True
  413.                 elif prefix == "-":
  414.                     role.all = False
  415.             elif cmd == "clear":
  416.                 if prefix == "+":
  417.                     role.whitelist = []
  418.                 elif prefix == "-":
  419.                     role.blacklist = []
  420.             else:
  421.                 if prefix == "+" and not cmd in role.whitelist:
  422.                     role.whitelist.append(cmd)
  423.                     if cmd in role.blacklist:
  424.                         role.blacklist.remove(cmd)
  425.                 elif prefix == "-" and not cmd in role.blacklist:
  426.                     role.blacklist.append(cmd)
  427.                     if cmd in role.whitelist:
  428.                         role.whitelist.remove(cmd)
  429.  
  430.         return True
  431.  
  432.     return False
  433.  
  434.  
  435.  
  436.  
  437. def load_roles():
  438.     f = open("data/roles.txt", "r")
  439.     for line in f:
  440.         spl = line.split("/+++/")
  441.         user_roles[spl[0]] = spl[1].replace("\n", "")
  442.     f.close()
  443.  
  444.  
  445. def set_role(user, role):
  446.     if role in permissions:
  447.         user_roles[user] = role
  448.         f = open("data/roles.txt", "w")
  449.         for user in user_roles.keys():
  450.             f.write(user+"/+++/"+user_roles[user]+"\n")
  451.         f.close()
  452.         return True
  453.     return False
  454.  
  455.  
  456. def get_role(user):
  457.     role = "DEFAULT"
  458.     if user not in user_roles:
  459.         set_role(user, "DEFAULT")
  460.     else:
  461.         role = user_roles[user]
  462.     if role in permissions:
  463.         return permissions[role]
  464.     return None
  465.  
  466.  
  467. def check_command(user, command, command_root=""):
  468.     role = get_role(user)
  469.     if role is not None:
  470.         return role.check(command, command_root)
  471.     return False
  472.  
  473.  
  474. global help_str, rng_help_str, song_help_str, msg_help_str, tag_help_str, role_help_str, money_help_str, activity_help_str, reward_help_str, shop_help_str, plugin_help_str
  475. def load_help_str(target, filename):
  476.     f = open(filename, "r")
  477.     for line in f:
  478.         target.append(line.replace("\n", "").replace("%c%", cfix()))
  479.     f.close()
  480.  
  481.  
  482. def load_help_strs():
  483.     global help_str, rng_help_str, song_help_str, msg_help_str, tag_help_str, role_help_str, money_help_str, activity_help_str, reward_help_str, shop_help_str, plugin_help_str
  484.     help_str = []
  485.     load_help_str(help_str, "help/help.txt")
  486.  
  487.     rng_help_str = []
  488.     load_help_str(rng_help_str, "help/rng.txt")
  489.  
  490.     song_help_str = []
  491.     load_help_str(song_help_str, "help/song.txt")
  492.  
  493.     msg_help_str = []
  494.     load_help_str(msg_help_str, "help/msg.txt")
  495.  
  496.  
  497.     tag_help_str = []
  498.     load_help_str(tag_help_str, "help/tag.txt")
  499.  
  500.     role_help_str = []
  501.     load_help_str(role_help_str, "help/role.txt")
  502.  
  503.     money_help_str = []
  504.     load_help_str(money_help_str, "help/money.txt")
  505.  
  506.     activity_help_str = []
  507.     load_help_str(activity_help_str, "help/activity.txt")
  508.  
  509.     reward_help_str = []
  510.     load_help_str(reward_help_str, "help/reward.txt")
  511.  
  512.     shop_help_str = []
  513.     load_help_str(shop_help_str, "help/shop.txt")
  514.  
  515.     plugin_help_str = []
  516.     load_help_str(plugin_help_str, "help/plugin.txt")
  517.  
  518.     if plugin_manager is not None:
  519.         plugin_manager.update_help()
  520.  
  521. class ShopItem:
  522.     def __init__(self, reward, price, name, short_desc, long_desc, hidden=False):
  523.         self.reward = reward
  524.         self.price = price
  525.         self.name = name
  526.         self.short_desc = short_desc
  527.         self.long_desc = long_desc
  528.         self.hidden = hidden
  529.         if type(self.long_desc) is str:
  530.             self.long_desc = [self.long_desc]
  531.  
  532.     def set_price(self, price):
  533.         self.price = price
  534.  
  535.     def set_short(self, desc):
  536.         self.short_desc = desc
  537.  
  538.     def set_long(self, long):
  539.         self.long_desc = long
  540.         if type(self.long_desc) is str:
  541.             self.long_desc = [self.long_desc]
  542.  
  543.     def add_long(self, long):
  544.         self.long_desc.append(long)
  545.  
  546.     def remove_long(self, line):
  547.         if line < 0:
  548.             line = len(self.long_desc) - line
  549.         else:
  550.             line -= 1
  551.         if line < len(self.long_desc):
  552.             del self.long_desc[line]
  553.             return True
  554.         return False
  555.  
  556.     def get_tagline(self):
  557.         if self.hidden:
  558.             return "["+self.name+"]" + " [$" + str(self.price) + "] - " + self.short_desc
  559.         else:
  560.             return self.name + " [$" + str(self.price) + "] - " + self.short_desc
  561.  
  562.     def get_long(self):
  563.         return "\n".join(self.long_desc)
  564.  
  565.     def get_save_str(self):
  566.         long_desc = "/+++/".join(self.long_desc)
  567.         return str(self.hidden) + "/+++/" + self.reward + "/+++/" + str(self.price) + "/+++/" + self.name + "/+++/" + self.short_desc + "/+++/" + long_desc
  568.  
  569. class Category:
  570.     def __init__(self, name, hidden=False):
  571.         self.name = name
  572.         self.items = {}
  573.         self.hidden = hidden
  574.  
  575.     def set_hidden(self, hidden, itemname=""):
  576.         if itemname == "":
  577.             self.hidden = hidden
  578.             return True
  579.         else:
  580.             item = self.get_item(itemname)
  581.             if item is not None:
  582.                 item.hidden = hidden
  583.                 return True
  584.         return False
  585.  
  586.     def add_item(self, item):
  587.         self.items[item.name] = item
  588.  
  589.     def remove_item(self, item):
  590.         if item is not None:
  591.             if item.name in self.items:
  592.                 del self.items[item.name]
  593.                 return True
  594.         return False
  595.  
  596.     def get_item(self, name):
  597.         name = name.lower()
  598.         for itemname in self.items.keys():
  599.             if name == itemname.lower():
  600.                 return self.items[itemname]
  601.         return None
  602.  
  603.     def move_item(self, item, dest):
  604.         if self.remove_item(item):
  605.             dest.add_item(item)
  606.             return True
  607.         return False
  608.  
  609.     def set_price(self, name, price):
  610.         item = self.get_item(name)
  611.         if item is not None:
  612.             item.set_price(price)
  613.             return True
  614.         return False
  615.  
  616.     def set_short(self, name, short):
  617.         item = self.get_item(name)
  618.         if item is not None:
  619.             item.set_short(short)
  620.             return True
  621.         return False
  622.  
  623.     def set_long(self, name, long):
  624.         item = self.get_item(name)
  625.         if item is not None:
  626.             item.set_long(long)
  627.             return True
  628.         return False
  629.  
  630.     def add_long(self, name, long):
  631.         item = self.get_item(name)
  632.         if item is not None:
  633.             item.add_long(long)
  634.             return True
  635.         return False
  636.  
  637.     def remove_long(self, name, line):
  638.         item = self.get_item(name)
  639.         if item is not None:
  640.             return item.remove_long(line)
  641.         return False
  642.  
  643. def get_item_desc(cat, itemname, show_hidden=False):
  644.     if itemname in cat.items:
  645.         item = cat.items[itemname]
  646.         if item.hidden and not show_hidden:
  647.             return ""
  648.         line = item.get_tagline() + "\n"
  649.         for desc in item.long_desc:
  650.             line = line + "   " + desc + "\n"
  651.         return line
  652.     return None
  653.  
  654. def get_shop_items(catname, show_hidden = False):
  655.     if catname in money_shop:
  656.         line = ""
  657.         cat = money_shop[catname]
  658.         for itemname in cat.items.keys():
  659.             if not cat.items[itemname].hidden or (cat.items[itemname].hidden and show_hidden):
  660.                 line = line + cat.items[itemname].get_tagline()
  661.         return line
  662.     return None
  663.  
  664. def get_cats(show_hidden=False):
  665.     line = ""
  666.     for catname in money_shop.keys():
  667.         if not money_shop[catname].hidden or (money_shop[catname].hidden and show_hidden):
  668.             cat = catname
  669.             if money_shop[cat].hidden:
  670.                 cat = "[" + cat + "]"
  671.             if line == "":
  672.                 line = cat
  673.             else:
  674.                 line = line + ", " + cat
  675.     return line
  676.  
  677. def get_items(catname, show_hidden=False):
  678.     if catname in money_shop:
  679.         line = ""
  680.         cat = money_shop[catname]
  681.         for itemname in cat.items.keys():
  682.             if not cat.items[itemname].hidden or (cat.items[itemname].hidden and show_hidden):
  683.                 item = itemname
  684.                 if cat.items[itemname].hidden:
  685.                     item = "[" + item + "]"
  686.                 if line == "":
  687.                     line = item
  688.                 else:
  689.                     line = line + ", " + item
  690.         return catname + ": " + line
  691.     return None
  692.  
  693. def add_item(catname, item):
  694.     if catname not in money_shop:
  695.         money_shop[catname] = Category(catname)
  696.     money_shop[catname].add_item(item)
  697.  
  698. def load_shop():
  699.     f = open("data/shop.txt", "r")
  700.     for line in f:
  701.         dat = line.replace("\n", "").split("/+++/")
  702.         item = ShopItem(dat[3], int(dat[4]), dat[5], dat[6], dat[7:], dat[2].lower() == "true")
  703.         add_item(dat[0], item)
  704.         money_shop[dat[0]].hidden = (dat[1].lower() == "true")
  705.     f.close()
  706.  
  707. def save_shop():
  708.     f = open("data/shop.txt", "w")
  709.     for catname in money_shop.keys():
  710.         for itemname in money_shop[catname].items.keys():
  711.             savestr = money_shop[catname].items[itemname].get_save_str()
  712.             f.write(catname + "/+++/" + str(money_shop[catname].hidden) + "/+++/" + savestr + "\n")
  713.     f.close()
  714.  
  715. def print_help(help_lines, page, max_lines=-1):
  716.     if max_lines == -1:
  717.         max_lines = mxlns()
  718.     pages = math.ceil((len(help_lines) - 1) / max_lines) - 1
  719.     if 0 <= page <= pages:
  720.         lines = ""
  721.         lines = lines + help_lines[0] + " (page " + str(page + 1) + " of " + str(pages + 1) + ")" + "\n"
  722.         for i in range((page * max_lines) + 1, min(len(help_lines), (page * max_lines) + 1 + max_lines)):
  723.             lines = lines + help_lines[i] + "\n"
  724.         return [lines]
  725.     return None
  726.  
  727.  
  728.  
  729.  
  730. def load_money():
  731.     f = open("data/money.txt", "r")
  732.     for line in f:
  733.         spl = line.replace("\n", "").split("=")
  734.         if spl[0] != "":
  735.             user_money[spl[0]] = int(spl[1])
  736.     f.close()
  737.  
  738. def save_money():
  739.     f = open("data/money.txt", "w")
  740.     for user in user_money.keys():
  741.         f.write(user+"="+str(user_money[user])+"\n")
  742.     f.close()
  743.  
  744. def get_money(user):
  745.     if user in user_money:
  746.         return user_money[user]
  747.     return 0
  748.  
  749. def give_money(user, amount):
  750.     if user not in user_money:
  751.         user_money[user] = amount
  752.         save_money()
  753.         return amount
  754.     else:
  755.         user_money[user] = user_money[user] + amount
  756.         save_money()
  757.         return user_money[user]
  758.  
  759.  
  760. def set_money(user, amount):
  761.     user_money[user] = amount
  762.     save_money()
  763.  
  764. def trade_money(user_from, user_to, amount):
  765.     if get_money(user_from) > amount:
  766.         give_money(user_from, amount)
  767.         give_money(user_to, amount)
  768.         return True
  769.     return False
  770.  
  771.  
  772. class Purger:
  773.     def __init__(self, const):
  774.         self.all = False
  775.         self.contains = []
  776.         self.not_contains = []
  777.         self.caps_contains = []
  778.         self.not_caps_contains = []
  779.         self.user = []
  780.         self.not_user = []
  781.         if const == "%all%":
  782.             self.all = True
  783.         else:
  784.             while "%" in const:
  785.                 index = const.find("%")
  786.                 const = const[index+1:]
  787.                 index = const.find("%")
  788.                 check_type = const[:index]
  789.                 const = const[index+1:]
  790.                 index = const.find("%")
  791.                 check = const[:index]
  792.                 const = const[index+1:]
  793.                 index = const.find("%")
  794.                 const = const[index+1:]
  795.                 if check_type.lower() == "c":
  796.                     self.contains.append(check)
  797.                 elif check_type.lower() == "nc":
  798.                     self.not_contains.append(check)
  799.                 elif check_type.lower() == "ic":
  800.                     self.caps_contains.append(check.lower())
  801.                 elif check_type.lower() == "inc":
  802.                     self.not_caps_contains.append(check.lower())
  803.                 elif check_type.lower() == "u":
  804.                     self.user.append(check.lower())
  805.                 elif check_type.lower() == "nu":
  806.                     self.not_user.append(check.lower())
  807.  
  808.  
  809.     def check(self, message):
  810.         if self.all:
  811.             return True
  812.         for check in self.contains:
  813.             if check in message.content:
  814.                 return True
  815.         for check in self.caps_contains:
  816.             if check.lower() in message.content.lower():
  817.                 return True
  818.         for check in self.not_contains:
  819.             if check in message.content:
  820.                 return False
  821.         for check in self.not_caps_contains:
  822.             if check in message.content.lower():
  823.                 return False
  824.         for check in self.user:
  825.             if message.author.name.lower() == check:
  826.                 return True
  827.         for check in self.not_user:
  828.             if message.author.name.lower() == check:
  829.                 return False
  830.         return True
  831.  
  832.  
  833. def load_rewards():
  834.     f = open("data/rewards.txt")
  835.     for line in f:
  836.         dat = line.replace("\n", "").split("/+++/")
  837.         if dat[0] != "":
  838.             rewards[dat[0]] = dat[1:]
  839.     f.close()
  840.  
  841. def save_rewards():
  842.     f = open("data/rewards.txt", "w")
  843.     for reward in rewards.keys():
  844.         f.write(reward+"/+++/" + "/+++/".join(rewards[reward]) + "\n")
  845.     f.close()
  846.  
  847. def set_reward(reward, commands):
  848.     rewards[reward] = commands
  849.     save_rewards()
  850.  
  851. def edit_reward(reward, commands, remove = False):
  852.     result = False
  853.     if remove:
  854.         if reward in rewards:
  855.             for command in commands:
  856.                 if command in rewards[reward]:
  857.                     rewards[reward].remove(command)
  858.             result = True
  859.     else:
  860.         if reward in rewards:
  861.             rewards[reward] = rewards[reward] + commands
  862.         else:
  863.             rewards[reward] = commands
  864.         result = True
  865.     save_rewards()
  866.     return result
  867.  
  868. def remove_reward(reward):
  869.     result = False
  870.     if reward in rewards:
  871.         del rewards[reward]
  872.         result = True
  873.     save_rewards()
  874.     return result
  875.  
  876. def get_reward(reward):
  877.     if reward in rewards:
  878.         return rewards[reward]
  879.     return None
  880.  
  881. # C%hello %
  882. global current_reward_checker
  883. current_reward_checker = None
  884. def reward_checker(message):
  885.     if current_reward_checker is not None:
  886.         return current_reward_checker.check(message)
  887.     return False
  888.  
  889. def use_reward(member, origin_channel, reward_arr):
  890.     if reward_arr is not None:
  891.         for reward in reward_arr:
  892.             data = reward.split("::")
  893.             if data[0] == "yoyo":
  894.                 if data[1] == "role":
  895.                     role = data[2]
  896.                     set_role(member.author.name, role)
  897.                 elif data[1] == "money":
  898.                     if data[2] == "give":
  899.                         give_money(member.name, int(data[3]))
  900.                     elif data[2] == "set":
  901.                         set_money(member.name, int(data[3]))
  902.                 elif data[1] == "say":
  903.                     channel_name = data[2].lower()
  904.                     channel = None
  905.                     if channel_name == ".":
  906.                         channel = origin_channel
  907.                     else:
  908.                         for ch in member.server.channels:
  909.                             if channel_name in ch.name.lower():
  910.                                 channel = ch
  911.                                 break
  912.                     if channel is not None:
  913.                         message = "::".join(data[3:])
  914.                         yield from client.send_message(channel, message)
  915.             elif data[0] == "discord":
  916.                 if data[1] == "role":
  917.                     role = None
  918.                     for r in member.server.roles:
  919.                         if data[3].lower() == r.name.lower():
  920.                             role = r
  921.                             break
  922.                     if role is not None:
  923.                         if data[2] == "add":
  924.                             yield from client.add_roles(member, role)
  925.                         elif data[2] == "remove":
  926.                             yield from client.remove_roles(member, role)
  927.                 elif data[1] == "nickname":
  928.                     yield from client.change_nickname(member, " ".join(data[2:]))
  929.                 elif data[1] == "mute":
  930.                     mute = False
  931.                     if data[2] == "true":
  932.                         mute = True
  933.                     yield from client.server_voice_state(member, mute=mute)
  934.                 elif data[1] == "purge":
  935.                     channel_name = data[2].lower()
  936.                     channel = None
  937.                     if channel_name == ".":
  938.                         channel = origin_channel
  939.                     else:
  940.                         for ch in member.server.channels:
  941.                             if channel_name in ch.name.lower():
  942.                                 channel = ch
  943.                                 break
  944.                     if channel is not None:
  945.                         limit = int(data[3])
  946.                         global current_reward_checker
  947.                         current_reward_checker = Purger("::".join(data[4:]))
  948.  
  949.                         yield from client.purge_from(channel, limit=limit, check=reward_checker)
  950.                 elif data[1] == "deafen":
  951.                     deafen = False
  952.                     if data[2] == "true":
  953.                         deafen = True
  954.                     yield from client.server_voice_state(member, deafen=deafen)
  955.                 elif data[1] == "invite":
  956.                     if data[2] == "server":
  957.                         max_age = 60
  958.                         max_uses = 1
  959.                         temporary = False
  960.                         if len(data) >= 4:
  961.                             max_age = int(data[3])
  962.                         if len(data) >= 5:
  963.                             max_uses = int(data[4])
  964.                         if len(data) >= 6:
  965.                             if data[5] == "true":
  966.                                 temporary = True
  967.                         inv = yield from client.create_invite(member.server, max_age=max_age, max_uses=max_uses, temporary=temporary)
  968.                         yield from client.send_message(member, inv.url)
  969.                     elif data[2] == "channel":
  970.                         channel_name = data[3].lower()
  971.                         channel = None
  972.                         if channel_name == ".":
  973.                             channel = origin_channel
  974.                         else:
  975.                             for ch in member.server.channels:
  976.                                 if channel_name in ch.name.lower():
  977.                                     channel = ch
  978.                                 break
  979.                         if channel is not None:
  980.                             max_age = 60
  981.                             max_uses = 1
  982.                             temporary = False
  983.                             if len(data) >= 3:
  984.                                 max_age = int(data[3])
  985.                             if len(data) >= 4:
  986.                                 max_uses = int(data[4])
  987.                             if len(data) >= 5:
  988.                                 if data[5] == "true":
  989.                                     temporary = True
  990.                             inv = yield from client.create_invite(channel, max_age=max_age, max_uses=max_uses, temporary=temporary)
  991.                             yield from client.send_message(member, inv.url)
  992.     return True
  993.  
  994.  
  995.  
  996.  
  997. def create_current_dat():
  998.     ts = time.localtime()
  999.     return DandT(ts.tm_yday, ts.tm_year, ts.tm_hour, ts.tm_min, ts.tm_sec)
  1000.  
  1001.  
  1002. class DandT:
  1003.     def __init__(self, d, y, h, m, s):
  1004.         self.day = int(d)
  1005.         self.year = int(y)
  1006.         self.hour = int(h)
  1007.         self.m = int(m)
  1008.         self.sec = int(s)
  1009.  
  1010.         self.user = None
  1011.  
  1012.     def get(self, i):
  1013.         if i == 0:
  1014.             return self.sec
  1015.         elif i == 1:
  1016.             return self.m
  1017.         elif i == 2:
  1018.             return self.hour
  1019.         elif i == 3:
  1020.             return self.day
  1021.         elif i == 4:
  1022.             return self.year
  1023.         else:
  1024.             return 0
  1025.  
  1026.     def set(self, i, v):
  1027.         if i == 0:
  1028.             self.sec = v
  1029.         elif i == 1:
  1030.             self.m = v
  1031.         elif i == 2:
  1032.             self.hour = v
  1033.         elif i == 3:
  1034.             self.day = v
  1035.         elif i == 4:
  1036.             self.year = v
  1037.  
  1038.     def max(self, i):
  1039.         if i == 0:
  1040.             return 60
  1041.         elif i == 1:
  1042.             return 60
  1043.         elif i == 2:
  1044.             return 24
  1045.         elif i == 3:
  1046.             return 365
  1047.         elif i == 4:
  1048.             return -1
  1049.         else:
  1050.             return 0
  1051.  
  1052.     def clone(self):
  1053.         return DandT(self.day, self.year, self.hour, self.m, self.sec)
  1054.  
  1055.     def greaterthan(self, dat):
  1056.         if self.year > dat.year:
  1057.             return True
  1058.         elif self.year == 0:
  1059.             if self.day > dat.dat:
  1060.                 return True
  1061.             elif self.day == 0:
  1062.                 if self.hour > dat.hour:
  1063.                     return True
  1064.                 elif self.hour == 0:
  1065.                     if self.m > dat.min:
  1066.                         return True
  1067.                     elif self.m == 0:
  1068.                         if self.sec > dat.sec:
  1069.                             return True
  1070.         return False
  1071.  
  1072.     def minus(self, dat):
  1073.  
  1074.         temp = dat.clone()
  1075.         result = DandT(0, 0, 0, 0, 0)
  1076.         for i in range(5):
  1077.             v1, v2 = self.get(i), temp.get(i)
  1078.             if v2 > v1:
  1079.                 if i == 4:
  1080.                     return None
  1081.                 result.set(i, (self.max(i) - v2) + v1)
  1082.                 temp.set(i + 1, temp.get(i + 1) + 1)
  1083.             else:
  1084.                 result.set(i, v1 - v2)
  1085.         # print( "["+self.full_format() + "] : [" + dat.full_format() +"] : [" + result.full_format() + "]")
  1086.         return result
  1087.  
  1088.     def cformat(self, form):
  1089.         return form.replace("%Y", str(self.year)).replace("%d", str(self.day)).replace("%H", str(self.hour)).replace(
  1090.             "%M", str(self.m)).replace("%S", str(self.sec))
  1091.  
  1092.     def clever_format(self):
  1093.         form = ""
  1094.         if self.year > 0:
  1095.             form = form + str(self.year) + " years "
  1096.         if self.day > 0 or form != "":
  1097.             form = form + str(self.day) + " days "
  1098.         if self.hour > 0 or form != "":
  1099.             form = form + str(self.hour) + " hours "
  1100.         if self.m > 0 or form != "":
  1101.             form = form + str(self.m) + " minutes "
  1102.         if self.sec > 0 or form != "":
  1103.             form = form + str(self.sec) + " seconds "
  1104.         return form
  1105.  
  1106.     def full_format(self):
  1107.         form = str(self.year) + " years " + str(self.day) + " days " \
  1108.                + str(self.hour) + " hours " + str(self.m) + " minutes " + str(self.sec) + " seconds"
  1109.         return form
  1110.  
  1111.     def full_quick_format(self):
  1112.         return self.cformat("%d/%Y at %H:%M:%S")
  1113.  
  1114.     def save_format(self):
  1115.         return self.cformat("%Y/+++/%d/+++/%H/+++/%M/+++/%S")
  1116.  
  1117.  
  1118. def add_user_record(name, dat):
  1119.     if "user_record" not in tag_stats:
  1120.         tag_stats["user_record"] = {}
  1121.     tag_stats["user_record"][name.lower()] = dat
  1122.  
  1123.  
  1124. def get_user_record(name):
  1125.     if "user_record" in tag_stats:
  1126.         if name in tag_stats["user_record"]:
  1127.             return tag_stats["user_record"][name]
  1128.     return None
  1129.  
  1130.  
  1131. def load_tag_stats():
  1132.     f = open("data/tag_stats.tag", "r")
  1133.     for ln in f:
  1134.         line = ln.replace("\n", "")
  1135.         if line != "":
  1136.             sp = line.split("/+++/")
  1137.             if sp[0] == "last_tag":
  1138.                 tag_stats["last_tag"] = DandT(sp[1], sp[2], sp[3], sp[4], sp[5])
  1139.             elif sp[0] == "record_longest":
  1140.                 dat = DandT(sp[2], sp[3], sp[4], sp[5], sp[6])
  1141.                 dat.user = sp[1]
  1142.                 tag_stats["record_longest"] = dat
  1143.             elif sp[0] == "user_record":
  1144.                 add_user_record(sp[1], DandT(sp[2], sp[3], sp[4], sp[5], sp[6]))
  1145.             elif sp[0] == "record_shortest":
  1146.                 dat = DandT(sp[2], sp[3], sp[4], sp[5], sp[6])
  1147.                 dat.user = sp[1]
  1148.                 tag_stats["record_shortest"] = dat
  1149.  
  1150.     f.close()
  1151.  
  1152.  
  1153. def save_tag_stats():
  1154.     f = open("data/tag_stats.tag", "w")
  1155.     if "last_tag" in tag_stats:
  1156.         f.write("last_tag/+++/" + tag_stats["last_tag"].save_format() + "\n")
  1157.     if "record_longest" in tag_stats:
  1158.         dat = tag_stats["record_longest"]
  1159.         f.write("record_longest/+++/" + dat.user + "/+++/" + dat.save_format() + "\n")
  1160.     if "record_shortest" in tag_stats:
  1161.         dat = tag_stats["record_shortest"]
  1162.         f.write("record_shortest/+++/" + dat.user + "/+++/" + dat.save_format() + "\n")
  1163.     if "user_record" in tag_stats:
  1164.         urs = tag_stats["user_record"]
  1165.         for user in urs.keys():
  1166.             f.write("user_record/+++/" + user + "/+++/" + urs[user].save_format() + "\n")
  1167.     f.close()
  1168.  
  1169.  
  1170. def finish_song():
  1171.     global song_finished, skip_votes, song_list, song_collection
  1172.     song_finished = True
  1173.     skip_votes = []
  1174.     if song_collection is not None:
  1175.         song_list = get_songlist(song_collection)
  1176.  
  1177.  
  1178. def next_song():
  1179.     global song_list, current_music_player, voice_chn, radio_channel, song_finished, recent_songs, song_queue, song_paused, song_volume
  1180.  
  1181.     #print(str(song_list))
  1182.     if len(song_list) > 0:
  1183.         if voice_chn is not None:
  1184.             song = None
  1185.             if len(song_queue) > 0:
  1186.                 song = song_queue[0]
  1187.                 song_queue.remove(song)
  1188.             else:
  1189.                 iter_cap = 0
  1190.                 while song in recent_songs and iter_cap < 20:
  1191.                     song = song_list[random.randint(0, len(song_list) - 1)]
  1192.                     iter_cap += 1
  1193.                 recent_songs.append(song)
  1194.                 if len(recent_songs) > rpcap():
  1195.                     recent_songs.remove(recent_songs[0])
  1196.             if song is not None:
  1197.                 current_music_player = yield from voice_chn.create_ytdl_player(song, after=finish_song)
  1198.                 current_music_player.volume = song_volume
  1199.                 song_finished = False
  1200.                 song_paused = False
  1201.                 if radio_channel is not None:
  1202.                     secs = current_music_player.duration
  1203.                     mins = math.floor(secs / 60)
  1204.                     secs -= (mins * 60)
  1205.                     strsecs = str(secs)
  1206.                     if len(strsecs) == 1:
  1207.                         strsecs = "0" + strsecs
  1208.                     yield from client.send_message(radio_channel,
  1209.                                                    "<SONG> Playing song: " + current_music_player.title + " [" + str(
  1210.                                                        mins) + ":" + strsecs + "] ")
  1211.                     yield from client.send_message(radio_channel, song)
  1212.                 else:
  1213.                     print(" no radio channel! ")
  1214.                 game = discord.Game()
  1215.                 game.name = current_music_player.title
  1216.                 yield from client.change_status(game, False)
  1217.                 current_music_player.start()
  1218.         else:
  1219.             current_music_player = None
  1220.             song_list = []
  1221.  
  1222.  
  1223. def start_radio(colls):
  1224.     global song_list, voice_chn, song_collection, song_paused
  1225.     if voice_chn is not None:
  1226.         song_finished = False
  1227.         song_paused = False
  1228.         song_collection = colls
  1229.         song_list = get_songlist(colls)
  1230.         yield from next_song()
  1231.  
  1232.  
  1233. def tag_player(name):
  1234.     global tagged, old_tagged
  1235.     old_tagged = tagged
  1236.     tagged = name
  1237.     f = open("data/tag.tag", "w")
  1238.     f.write(name + "\n")
  1239.     f.write(old_tagged)
  1240.     f.close()
  1241.  
  1242.     lt = None
  1243.     if "last_tag" in tag_stats:
  1244.         lt = tag_stats["last_tag"]
  1245.     if lt is None:
  1246.         tag_stats["last_tag"] = create_current_dat()
  1247.     else:
  1248.         newdt = create_current_dat()
  1249.         elap = newdt.minus(lt)
  1250.         elap.user = old_tagged
  1251.         record = get_user_record(old_tagged)
  1252.         if record is None:
  1253.             add_user_record(name, elap)
  1254.         elif elap.greaterthan(record):
  1255.             add_user_record(name, elap)
  1256.         if "record_longest" in tag_stats:
  1257.             longest = tag_stats["record_longest"]
  1258.             if elap.greaterthan(longest):
  1259.                 tag_stats["record_longest"] = elap
  1260.         else:
  1261.             tag_stats["record_longest"] = elap
  1262.         if "record_shortest" in tag_stats:
  1263.             shortest = tag_stats["record_shortest"]
  1264.             if shortest.greaterthan(elap):
  1265.                 tag_stats["record_shortest"] = elap
  1266.         else:
  1267.             tag_stats["record_shortest"] = elap
  1268.         tag_stats["last_tag"] = newdt
  1269.     save_tag_stats()
  1270.  
  1271.  
  1272. def load_tag():
  1273.     global tagged, old_tagged
  1274.     f = open("data/tag.tag", "r")
  1275.     for line in f:
  1276.         if line != "" and line != "\n":
  1277.             if tagged == "":
  1278.                 tagged = line.replace("\n", "")
  1279.             elif old_tagged == "":
  1280.                 old_tagged = line.replace("\n", "")
  1281.                 break
  1282.     f.close()
  1283.  
  1284.  
  1285. def add_collection(collection):
  1286.     songs[collection] = []
  1287.     collections.append(collection)
  1288.     f = open("data/collections.txt", "w")
  1289.     for col in collections:
  1290.         f.write(col + "\n")
  1291.     f.close()
  1292.  
  1293.  
  1294. def add_song(collection, songname):
  1295.     if collection not in collections:
  1296.         add_collection(collection)
  1297.     songs[collection].append(songname)
  1298.     f = open("playlists/" + collection + ".sng", "w")
  1299.     for song in songs[collection]:
  1300.         f.write(song + "\n")
  1301.     f.close()
  1302.  
  1303.  
  1304. def remove_song(collection, songname):
  1305.     if collection in collections:
  1306.         if songname in songs[collection]:
  1307.             songs[collection].remove(songname)
  1308.             f = open("playlists/" + collection + ".sng", "w")
  1309.             for song in songs[collection]:
  1310.                 f.write(song + "\n")
  1311.             f.close()
  1312.             return True
  1313.         else:
  1314.             print("couldn't find song: " + songname)
  1315.             print(songs[collection])
  1316.     else:
  1317.         print("couldn't find collection: " + collection)
  1318.     return False
  1319.  
  1320.  
  1321. def get_songlist(colls):
  1322.     songlist = []
  1323.     for coll in colls:
  1324.         if coll in collections:
  1325.             for song in songs[coll]:
  1326.                 cur = song.replace("\n", "")
  1327.                 if cur not in songlist:
  1328.                     songlist.append(cur)
  1329.     return songlist
  1330.  
  1331.  
  1332. def get_song(colls):
  1333.     songlist = get_songlist(colls)
  1334.     if len(songlist) > 0:
  1335.         return songlist[random.randint(0, len(songlist) - 1)]
  1336.     return None
  1337.  
  1338.  
  1339. def add_history(username):
  1340.     for i in range(0, len(msg_history) - 1):
  1341.         j = len(msg_history) - (i + 1)
  1342.         msg_history[j] = msg_history[j - 1]
  1343.     msg_history[0] = username
  1344.  
  1345.  
  1346. def load_songs():
  1347.     f = open("data/collections.txt", "r")
  1348.     for line in f:
  1349.         if line != "" and line != "\n":
  1350.             collections.append(line.replace('\n', ''))
  1351.     f.close()
  1352.     for col in collections:
  1353.         songs[col] = []
  1354.         f = open("playlists/"+col + ".sng")
  1355.         for line in f:
  1356.             if line != "" and line != "\n":
  1357.                 songs[col].append(line.replace("\n", ""))
  1358.         f.close()
  1359.  
  1360.  
  1361. def add_nick(name, nick):
  1362.     name = name.lower()
  1363.     nick = nick.lower()
  1364.     if name not in nick_players:
  1365.         nick_players.append(name)
  1366.     nicknames[name] = nick
  1367.     f = open("data/nicknames.txt", "w")
  1368.     for player in nick_players:
  1369.         f.write(player.lower() + "=|=" + nicknames[player].lower() + "\n")
  1370.     f.close()
  1371.  
  1372.  
  1373. def load_nicks():
  1374.     f = open("data/nicknames.txt", "r")
  1375.     for line in f:
  1376.         spl = line.split("=|=")
  1377.         player = spl[0].replace("\n", "")
  1378.         nickname = spl[1].replace("\n", "")
  1379.         nick_players.append(player)
  1380.         nicknames[player] = nickname
  1381.     f.close()
  1382.  
  1383.  
  1384. xkcd_range = [100, 1600]
  1385.  
  1386.  
  1387. def get_xkcd_link(n):
  1388.     link = "http://xkcd.com/" + str(n) + "/"
  1389.     f = requests.get(link)
  1390.     lines = f.text.split('\n')
  1391.     imgurl = None
  1392.     for line in lines:
  1393.         if line.startswith("Image URL"):
  1394.             line = line.replace(" ", "")
  1395.             index = line.find("http")
  1396.             imgurl = line[index:]
  1397.             break
  1398.     return imgurl
  1399.  
  1400. def download_plugin(link, name):
  1401.  
  1402.     print("   [PLUGIN] sending request to " + link + "...")
  1403.     f = requests.get(link)
  1404.     print("   [PLUGIN] creating file "+name+".py ...")
  1405.     dest = open("plugins/"+name+".py", "w")
  1406.     print("   [PLUGIN] dumping data...")
  1407.     dest.write("#SOURCE/+++/"+link+"/+++/"+name+"\n")
  1408.     dest.write(f.text)
  1409.     dest.close()
  1410.     print("   [PLUGIN] done")
  1411.  
  1412. def update_plugin(name):
  1413.     if os.path.exists("plugins/"+name+".py"):
  1414.         f = open("plugins/"+name+".py")
  1415.         for line in f:
  1416.             if line.startswith("#SOURCE"):
  1417.                 spl = line.replace("\n", "").split("/+++/")
  1418.                 download_plugin(spl[1], spl[2])
  1419.                 return True
  1420.     return False
  1421.  
  1422. def get_metapic(n=-1):
  1423.     link = "http://themetapicture.com/"
  1424.     f = requests.get(link)
  1425.  
  1426.     lines = f.text.split("\n")
  1427.     images = []
  1428.  
  1429.     for line in lines:
  1430.         if "<p><img src=" in line:
  1431.             index = line.find("img src=")
  1432.             imglink = line[index + 9:]
  1433.             index = imglink.find(" ")
  1434.             imglink = imglink[:index - 1]
  1435.             images.append(imglink)
  1436.     if n == -1:
  1437.         n = random.randint(0, len(images) - 1)
  1438.     else:
  1439.         n = min(len(images) - 1, max(0, n))
  1440.     return images[n]
  1441.  
  1442.  
  1443. cah_range = [100, 4300]
  1444.  
  1445.  
  1446. def get_cah_link(n):
  1447.     link = "http://explosm.net/comics/" + str(n) + "/"
  1448.     f = requests.get(link)
  1449.     lines = f.text.split('\n')
  1450.     imgurl = None
  1451.     for line in lines:
  1452.         if line.startswith("<meta property") and "og:image" in line:
  1453.             line = line.replace(" ", "")
  1454.             index = line.find("http")
  1455.             imgurl = line[index:]
  1456.             imgurl = imgurl[:-2]
  1457.             break
  1458.     return imgurl
  1459.  
  1460.  
  1461. def get_humblebundle(suffix=""):
  1462.     link = "https://www.humblebundle.com/" + suffix
  1463.     f = requests.get(link)
  1464.  
  1465.     lines = f.text.split('\n')
  1466.     base_games = ""
  1467.     average_games = ""
  1468.     average_price = "???"
  1469.     bonus_games = ""
  1470.     bonus_price = "???"
  1471.  
  1472.     game_index = 0
  1473.     last_line = None
  1474.     for line in lines:
  1475.         if "prepend section-heading price bta" in line and game_index == 0:
  1476.             game_index = 1
  1477.             index = line.find("$")
  1478.             average_price = line[index:]
  1479.             index = average_price.find(" ")
  1480.             average_price = average_price[:index]
  1481.         if "prepend section-heading price fixed" in line and game_index == 1:
  1482.             game_index = 2
  1483.             index = line.find("$")
  1484.             bonus_price = line[index:]
  1485.             index = bonus_price.find(" ")
  1486.             bonus_price = bonus_price[:index]
  1487.         if "section game-border prepend coupons" in line:
  1488.             break
  1489.         if "<h2>" in line and "game-description" in last_line:
  1490.             index = line.find("<h2>")
  1491.             gamename = line[index + 4:]
  1492.             gamename = gamename[:-5]
  1493.             if game_index == 0:
  1494.                 base_games = base_games + "    - " + gamename + "\n"
  1495.             elif game_index == 1:
  1496.                 average_games = average_games + "     - " + gamename + "\n"
  1497.             else:
  1498.                 bonus_games = bonus_games + "     - " + gamename + "\n"
  1499.         last_line = line
  1500.     return "BASE GAMES ($1):\n" + base_games + "\n" + "AVERAGE GAMES (" + average_price + "):\n" + average_games + "\n" + "BONUS GAMES (" + bonus_price + "):\n" + bonus_games
  1501.  
  1502.  
  1503. def get_name(name):
  1504.     name = name.lower()
  1505.     for nm in nick_players:
  1506.         if nicknames[nm] == name:
  1507.             return nm
  1508.     return name
  1509.  
  1510. def add_raw_activity(member, origin_channel, amount):
  1511.     name = member.name.lower()
  1512.     old_activity = activity[name]
  1513.     activity[name] += amount
  1514.     for trigger in activity_triggers:
  1515.         if old_activity < trigger <= activity[name]:
  1516.             yield from use_reward(member, origin_channel, get_reward(activity_triggers[trigger]))
  1517.     save_activity()
  1518.  
  1519. def add_activity(member, origin_channel, act):
  1520.     global activity, activity_events, activity_cds
  1521.     save_acts = False
  1522.     name = member.name.lower()
  1523.     if name is not botname():
  1524.         if name not in activity:
  1525.             activity[name] = 0
  1526.             save_acts = True
  1527.         secs = time.time()
  1528.         if name not in activity_cds:
  1529.             activity_cds[name] = {}
  1530.  
  1531.         if act not in activity_cds[name]:
  1532.             activity_cds[name][act] = secs
  1533.  
  1534.         if activity_cds[name][act] <= secs:
  1535.             amount = 0
  1536.             cd = 0
  1537.             if act in activity_events:
  1538.                 amount = activity_events[act][0]
  1539.                 cd = activity_events[act][1]
  1540.             if amount > 0:
  1541.                 yield from add_raw_activity(member, origin_channel, amount)
  1542.                 activity_cds[name][act] = secs + cd
  1543.                 save_acts = False
  1544.  
  1545.         if save_acts:
  1546.             save_activity()
  1547.  
  1548.  
  1549.  
  1550. def save_activity():
  1551.     f = open("data/activity.txt", "w")
  1552.     for name in activity.keys():
  1553.         f.write(name + "/+++/" + str(activity[name]) + "\n")
  1554.     f.close()
  1555.  
  1556.  
  1557. def load_activity():
  1558.     global activity
  1559.     f = open("data/activity.txt", "r")
  1560.     for line in f:
  1561.         tabs = line.replace("\n", "").split("/+++/")
  1562.         if tabs[0] != "":
  1563.             activity[tabs[0]] = int(tabs[1])
  1564.     f.close()
  1565.  
  1566. def load_activity_events():
  1567.     f = open("data/activity_events.txt", "r")
  1568.     for line in f:
  1569.         tabs = line.replace("\n", "").split(":")
  1570.         activity_events[tabs[0]] = [int(tabs[1]), int(tabs[2])]
  1571.     f.close()
  1572.  
  1573. def save_activity_events():
  1574.     f = open("data/activity_events.txt", "w")
  1575.     for act in activity_events:
  1576.         f.write(act+":"+str(activity_events[act][0])+":"+str(activity_events[act][1]) + "\n")
  1577.     f.close()
  1578.  
  1579. def load_activity_triggers():
  1580.     f = open("data/activity_triggers.txt", "r")
  1581.     for line in f:
  1582.         tabs = line.replace("\n", "").split("/+++/")
  1583.         activity_triggers[int(tabs[0])] = tabs[1]
  1584.     f.close()
  1585.  
  1586. def save_activity_triggers():
  1587.     f = open("data/activity_triggers.txt", "w")
  1588.     for trigger in activity_triggers.keys():
  1589.         f.write(str(trigger)+"/+++/"+activity_triggers[trigger] + "\n")
  1590.     f.close()
  1591.  
  1592. def save_messages():
  1593.     f = open("data/msgs.txt", "w")
  1594.     for name in left_messages.keys():
  1595.         if len(left_messages[name]) > 0:
  1596.             line = name + "/+++/" + left_messages[name][0]
  1597.             for i in range(1, len(left_messages[name])):
  1598.                 line = line + "/+++/" + left_messages[name][i]
  1599.             f.write(line + "\n")
  1600.     f.close()
  1601.  
  1602.  
  1603. def load_messages():
  1604.     f = open("data/msgs.txt", "r")
  1605.     for line in f:
  1606.         if line != '' and line != '\n':
  1607.             spl = line.replace('\n', '').split("/+++/")
  1608.             name = spl[0]
  1609.             left_messages[name] = []
  1610.             for i in range(1, len(spl)):
  1611.                 left_messages[name].append(spl[i])
  1612.     f.close()
  1613.  
  1614.  
  1615. def leave_message(name, msg):
  1616.     name = name.lower()
  1617.     if name not in left_messages:
  1618.         left_messages[name] = []
  1619.     left_messages[name].append(msg)
  1620.     save_messages()
  1621.  
  1622.  
  1623. def get_messages(name):
  1624.     name = name.lower()
  1625.     msgs = []
  1626.     if name in left_messages:
  1627.         msgs = left_messages[name]
  1628.     return msgs
  1629.  
  1630. @client.event
  1631. @asyncio.coroutine
  1632. def on_message_delete(message):
  1633.     yield from add_activity(message.author, message.channel, "on_message_delete")
  1634.     yield from plugin_manager.on_message_delete(message)
  1635.  
  1636. @client.event
  1637. @asyncio.coroutine
  1638. def on_member_join(member):
  1639.     yield from add_activity(member, member, "on_member_join")
  1640.     yield from plugin_manager.on_member_join(member)
  1641.  
  1642. @client.event
  1643. @asyncio.coroutine
  1644. def on_member_remove(member):
  1645.     yield from add_activity(member, member, "on_member_remove")
  1646.     yield from plugin_manager.on_member_remove(member)
  1647.  
  1648. @client.event
  1649. @asyncio.coroutine
  1650. def on_member_update(before, after):
  1651.     yield from add_activity(after, after, "on_member_update")
  1652.     yield from plugin_manager.on_member_update(before, after)
  1653.  
  1654. @client.event
  1655. @asyncio.coroutine
  1656. def on_voice_state_update(before, after):
  1657.     yield from add_activity(after, after, "on_voice_state")
  1658.     yield from plugin_manager.on_voice_state_update(before, after)
  1659.  
  1660. @client.event
  1661. @asyncio.coroutine
  1662. def on_member_ban(member):
  1663.     yield from add_activity(member, member, "on_ban")
  1664.     yield from plugin_manager.on_member_ban(member)
  1665.  
  1666. @client.event
  1667. @asyncio.coroutine
  1668. def on_member_unban(member):
  1669.     yield from add_activity(member, member, "on_unban")
  1670.     yield from plugin_manager.on_member_unban(member)
  1671.  
  1672. @client.event
  1673. @asyncio.coroutine
  1674. def on_typing(ch, user, when):
  1675.     yield from add_activity(user, ch, "on_typing")
  1676.     yield from plugin_manager.on_typing(ch, user, when)
  1677.  
  1678. @client.event
  1679. @asyncio.coroutine
  1680. def on_message(message):
  1681.     global tagged
  1682.     yield from add_activity(message.author, message.channel, "on_message")
  1683.     sucess = False
  1684.     if message.author.name.lower() != botname():
  1685.         if not message.content.startswith(cfix()) and not message.channel.is_private and len(message.content) < taglimit():
  1686.             if message.author.name.lower() == tagged:
  1687.                 for member in message.author.server.members:
  1688.                     memname = member.name.lower()
  1689.                     if memname != message.author.name.lower():
  1690.                         if memname in nick_players:
  1691.                             if nicknames[memname] in message.content.lower():
  1692.                                 tag_player(memname)
  1693.                                 break
  1694.         welcome(message.author)
  1695.         global radio_channel
  1696.         if is_command(message.content, "yoyo"):
  1697.             if not check_command(message.author.name, "yoyo"):
  1698.                 yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1699.             else:
  1700.                 msg = message.content[message.content.find(" ")+1:]
  1701.                 yield from client.send_message(message.channel, msg)
  1702.                 add_history(message.author.name)
  1703.                 sucess = True
  1704.         elif is_command(message.content, "yoyosay"):
  1705.             if not check_command(message.author.name, "yoyosay"):
  1706.                 yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1707.             else:
  1708.                 msg = message.content[message.content.find(" ")+1:]
  1709.                 yield from client.send_message(message.channel, msg, tts=True)
  1710.                 add_history(message.author.name)
  1711.                 sucess = True
  1712.         elif is_command(message.content, "activity"):
  1713.             formatting = ": use "+cfix()+"activity to check | "+cfix()+"activity add/set <username> <amount> to add/set amount"
  1714.             try:
  1715.                 params = [""]
  1716.                 if " " in message.content:
  1717.                     params = message.content[message.content.find(" ")+1:].split(" ")
  1718.                 if params[0] == "add":
  1719.                     formatting = ": "+cfix()+"activity add <username> <amount>"
  1720.                     if not check_command(message.author.name, "activity set", "activity"):
  1721.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1722.                     else:
  1723.                         name = params[1].lower()
  1724.                         member = None
  1725.                         for mem in message.author.server.members:
  1726.                             if name in mem.name.lower():
  1727.                                 member = mem
  1728.                                 name = mem.name.lower()
  1729.                                 break
  1730.                         if member is not None:
  1731.                             v = int(params[2])
  1732.                             yield from add_raw_activity(member, message.channel, v)
  1733.                             yield from client.send_message(message.channel, "<ACV> Added " + str(v) + " activity to " + name + "'s account")
  1734.                             sucess = True
  1735.                         else:
  1736.                             yield from client.send_message(message.channel, "<ACV> Could not find player " + params[1])
  1737.                 elif params[0] == "set":
  1738.                     formatting = ": "+cfix()+"activity set <username> <amount>"
  1739.                     if not check_command(message.author.name, "activity set", "activity"):
  1740.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1741.                     else:
  1742.                         name = params[1].lower()
  1743.                         member = None
  1744.                         for mem in message.author.server.members:
  1745.                             if name in mem.name.lower():
  1746.                                 member = mem
  1747.                                 name = mem.name.lower()
  1748.                                 break
  1749.  
  1750.                         if member is not None:
  1751.                             v = 0
  1752.                             if name in activity:
  1753.                                 v = activity[name]
  1754.                             yield from add_raw_activity(member, message.channel, int(params[2]) - v)
  1755.                             yield from client.send_message(message.channel, "<ACV> Set " + name + "'s activity to " + params[2])
  1756.                             sucess = True
  1757.                         else:
  1758.                             yield from client.send_message(message.channel, "<ACV> Could not find player " + params[1])
  1759.                 elif params[0] == "trigger":
  1760.                     formatting = ": "+cfix()+"activity trigger [activity_amount|remove|get] [reward|activity_amount]"
  1761.                     if not check_command(message.author.name, "activity trigger", "activity"):
  1762.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1763.                     else:
  1764.                         if len(params) == 1:
  1765.                             formatting = ": "+cfix()+"activity trigger"
  1766.                             joint = ""
  1767.                             if len(activity_triggers.keys()) > 0:
  1768.                                 for activity_amount in activity_triggers.keys():
  1769.                                     if joint == "":
  1770.                                         joint = str(activity_amount)
  1771.                                     else:
  1772.                                         joint = joint + ", " + str(activity_amount)
  1773.                             yield from client.send_message(message.channel, "<ACV> Current triggers: " + joint)
  1774.                         elif params[1] == "get":
  1775.                             formatting = ": "+cfix()+"activity trigger get <activity_amount>"
  1776.                             amount = int(params[2])
  1777.                             if amount in activity_triggers:
  1778.                                 yield from client.send_message(message.channel, "<ACV> Reward for " + str(amount) + " activity is " + activity_triggers[amount])
  1779.                             else:
  1780.                                 yield from client.send_message(message.channel, "<ACV> Activity trigger for " + str(amount) + " doesn't exist!")
  1781.                         elif params[1] == "remove":
  1782.                             formatting = ": "+cfix()+"activity trigger remove <activity_amount>"
  1783.                             amount = int(params[2])
  1784.                             if amount in activity_triggers:
  1785.                                 del activity_triggers[amount]
  1786.                                 save_activity_triggers()
  1787.                                 yield from client.send_message(message.channel, "<ACV> Removed activity trigger for " + str(amount))
  1788.                             else:
  1789.                                 yield from client.send_message(message.channel, "<ACV> Activity trigger for " + str(amount) + " doesn't exist!")
  1790.                         else:
  1791.                             formatting = ": "+cfix()+"activity trigger <activity_amount> <reward>"
  1792.                             amount = int(params[1])
  1793.                             reward = params[2]
  1794.                             activity_triggers[amount] = reward
  1795.                             save_activity_triggers()
  1796.                             yield from client.send_message(message.channel, "<ACV> Added a new activity trigger!")
  1797.                             sucess = True
  1798.                 elif params[0] == "event":
  1799.                     formatting = ": "+cfix()+"activity event <event> <activity_given> [cooldown]"
  1800.                     if not check_command(message.author.name, "activity event", "activity"):
  1801.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1802.                     else:
  1803.                         event = params[1].lower()
  1804.                         amount = int(params[2])
  1805.                         cooldown = 0
  1806.                         if len(params) > 3:
  1807.                             cooldown = int(params[4])
  1808.                         if event in activity_events:
  1809.                             activity_events[event]
  1810.                             activity_events[event] = [amount, cooldown]
  1811.                             save_activity_events()
  1812.                             yield from client.send_message(message.channel, "<ACV> Set " + event + " to give " + str(amount) + " on a " + str(cooldown) + " second cooldown")
  1813.                             sucess = True
  1814.                         else:
  1815.                             yield from client.send_message(message.channel, "<ACV> Invalid event!")
  1816.                 elif params[0] == "get":
  1817.                     formatting = ": "+cfix()+"activity get <event>"
  1818.                     if not check_command(message.author.name, "activity get", "activity"):
  1819.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1820.                     else:
  1821.                         event = params[1].lower()
  1822.                         if event in activity_events:
  1823.                             info = activity_events[event]
  1824.                             yield from client.send_message(message.channel, "<ACV> Set " + event + " to give " + str(info[0]) + " on a " + str(info[1]) + " second cooldown")
  1825.                             sucess = True
  1826.                         else:
  1827.                             yield from client.send_message(message.channel, "<ACV> Invalid event!")
  1828.                 elif params[0] == "help":
  1829.                     if not check_command(message.author.name, "activity help", "activity"):
  1830.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1831.                     else:
  1832.                         formatting = ": "+cfix()+"activity help"
  1833.                         page = 0
  1834.                         if len(params) > 1:
  1835.                             page = int(params[1]) - 1
  1836.                         lines = print_help(activity_help_str, page)
  1837.                         if lines is not None:
  1838.                             for line in lines:
  1839.                                 yield from client.send_message(message.author, line)
  1840.                             sucess = True
  1841.                         else:
  1842.                             yield from client.send_message(message.channel, "<ACV> invalid page!")
  1843.                 else:
  1844.                     formatting = ": "+cfix()+"activity [username]"
  1845.                     if not check_command(message.author.name, "activity check", "activity"):
  1846.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1847.                     else:
  1848.                         name = message.author.name.lower()
  1849.                         if params[0] != "":
  1850.                             name = params[0].lower()
  1851.                             for mem in message.author.server.members:
  1852.                                 if name in mem.name.lower():
  1853.                                     name = mem.name.lower()
  1854.                                     break
  1855.                         v = 0
  1856.                         if name in activity:
  1857.                             v = activity[name]
  1858.                         yield from client.send_message(message.channel, "<ACV> " + name + "'s activity is " + str(v))
  1859.                     sucess = True
  1860.             except:
  1861.                 yield from client.send_message(message.channel, "<ACV> Failed" + formatting)
  1862.         elif is_command(message.content, "tagged"):
  1863.             formatting = ": see "+cfix()+"tagged help"
  1864.             try:
  1865.                 params = [""]
  1866.                 if " " in message.content:
  1867.                     params = message.content[message.content.find(" ")+1:].split(" ")
  1868.                 if params[0] == "":
  1869.                     formatting = ": "+cfix()+"tagged"
  1870.                     if not check_command(message.author.name, "tagged check", "tagged"):
  1871.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1872.                     else:
  1873.                         cur = tagged
  1874.                         if message.author.name.lower() == tagged:
  1875.                             cur = old_tagged
  1876.                         yield from client.send_message(message.author, "<TAG> " + cur + " is currently tagged, shhh")
  1877.                         sucess = True
  1878.                 elif params[0] == "best":
  1879.                     if not check_command(message.author.name, "tagged best", "tagged"):
  1880.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1881.                     else:
  1882.                         formatting = ": "+cfix()+"tagged best"
  1883.                         if "record_shortest" in tag_stats:
  1884.                             record = tag_stats["record_shortest"]
  1885.                             yield from client.send_message(message.channel, "<TAG> " + record.user + " currently holds the record for shortest time tagged, with " + record.clever_format())
  1886.                         else:
  1887.                             yield from client.send_message(message.channel, "<TAG> no record set yet!")
  1888.                         sucess = True
  1889.                 elif params[0] == "worst":
  1890.                     if not check_command(message.author.name, "tagged worst", "tagged"):
  1891.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1892.                     else:
  1893.                         formatting = ": "+cfix()+"tagged worst [username]"
  1894.                         if len(params) > 1:
  1895.                             if "user_record" in tag_stats:
  1896.                                 name = get_name(params[1])
  1897.                                 if name in tag_stats["user_record"]:
  1898.                                     record = tag_stats["user_record"]
  1899.                                     client.send_message(message.channel, "<TAG> " + name + "'s record for longest time tagged is " + record.clever_format())
  1900.                                 else:
  1901.                                     yield from client.send_message(message.channel, "<TAG> " + name + " has no record yet!")
  1902.                             else:
  1903.                                 yield from client.send_message(message.channel, "<TAG> nobody has a record yet!")
  1904.                         else:
  1905.                             if "record_longest" in tag_stats:
  1906.                                 record = tag_stats["record_longest"]
  1907.                                 client.send_message(message.channel,
  1908.                                                     "<TAB> " + record.user + " currently holds the record for the longest time tagged, with " + record.clever_format())
  1909.                             else:
  1910.                                 yield from client.send_message(message.channel, "<TAG> no record set yet!")
  1911.                         sucess = True
  1912.                 elif params[0] == "help":
  1913.                     if not check_command(message.author.name, "tagged help", "tagged"):
  1914.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1915.                     else:
  1916.                         formatting = ": "+cfix()+"tagged help"
  1917.                         page = 0
  1918.                         if len(params) > 1:
  1919.                             page = int(params[1]) - 1
  1920.                         lines = print_help(tag_help_str, page)
  1921.                         if lines is not None:
  1922.                             for line in lines:
  1923.                                 yield from client.send_message(message.author, line)
  1924.                             sucess = True
  1925.                         else:
  1926.                             yield from client.send_message(message.channel, "<TAG> invalid page!")
  1927.                 else:
  1928.                     raise(Exception())
  1929.             except():
  1930.                 yield from client.send_message(message.channel, "<TAG> Failed, do it properly" + formatting)
  1931.         elif is_command(message.content, "history"):
  1932.             if not check_command(message.author.name, "history"):
  1933.                 yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1934.             else:
  1935.                 msg = "<YOYO> History: " + msg_history[0]
  1936.                 for i in range(1, len(msg_history)):
  1937.                     if msg_history[i] != "":
  1938.                         msg = msg + ", " + msg_history[i]
  1939.                 yield from client.send_message(message.channel, msg)
  1940.                 sucess = True
  1941.         elif is_command(message.content, "hman"):
  1942.  
  1943.             formatting = ": see "+cfix()+"hangman help"
  1944.             try:
  1945.                 global hangman_found, hangman_word, hangman_words, hangman_guess, hangman_guessed_letters, hangman_tries
  1946.                 params = [""]
  1947.                 if " " in message.content:
  1948.                     params = message.content[message.content.find(" ")+1:].split(" ")
  1949.                 if params[0] == "":
  1950.                     if not check_command(message.author.name, "hman check", "hman"):
  1951.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1952.                     else:
  1953.                         if hangman_word != "":
  1954.                             yield from client.send_message(message.channel, "<HMAN> Current progress: " + str(
  1955.                                 hangman_found) + " with " + str(
  1956.                                 hangman_guess) + " (bad) guesses left. Wrong letters guessed: " + hangman_guessed_letters)
  1957.                         else:
  1958.                             yield from client.send_message(message.channel, "<HMAN> No game in-progress!")
  1959.                 elif params[0] == "help":
  1960.                     if not check_command(message.author.name, "hman help", "hman"):
  1961.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1962.                     else:
  1963.                         yield from client.send_message(message.channel, "<HMAN> ("+cfix()+"hman can be used as well) "+cfix()+"hangman to check progress, "+cfix()+"hangman new [word] create new game, random word if none given, "+cfix()+"hangman [letter|word] guess a word or a letter, "+cfix()+"hangman end to give up")
  1964.                 elif params[0] == "new":
  1965.                     if not check_command(message.author.name, "hman new", "hman"):
  1966.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1967.                     else:
  1968.                         hangman_word = hangman_words[random.randint(0, len(hangman_words) - 1)]
  1969.                         if len(params) > 1:
  1970.                             hangman_word = params[1]
  1971.                             for i in range(2, len(params)):
  1972.                                 hangman_word = hangman_word + " " + params[i]
  1973.                         hangman_found = "-" * len(hangman_word)
  1974.                         for i in range(len(hangman_word)):
  1975.                             if hangman_word[i] == " ":
  1976.                                 hangman_found = hangman_found[:i] + " " + hangman_found[i + 1:]
  1977.                         yield from client.send_message(message.channel, "<HMAN> New game created: " + str(hangman_found))
  1978.                         hangman_guess = 9
  1979.                         hangman_guessed_letters = ""
  1980.                         hangman_tries = 0
  1981.  
  1982.                 elif params[0] == "end":
  1983.                     if not check_command(message.author.name, "hman end", "hman"):
  1984.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1985.                     else:
  1986.                         yield from client.send_message(message.channel, "<HMAN> Failed! The word was: " + str(
  1987.                             hangman_word) + " you got " + hangman_found + " in " + str(hangman_tries) + " tries!")
  1988.                         hangman_word = ""
  1989.                         hangman_found = ""
  1990.                         hangman_guess = 0
  1991.                         hangman_guessed_letters = ""
  1992.                         hangman_tries = 0
  1993.                 elif hangman_word != "":
  1994.                     if not check_command(message.author.name, "hman guess", "hman"):
  1995.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  1996.                     else:
  1997.                         letter = params[0].lower()
  1998.                         if len(letter) == 1:
  1999.                             if letter not in hangman_guessed_letters:
  2000.                                 hangman_tries += 1
  2001.                                 if letter in hangman_word:
  2002.                                     old_found = hangman_found
  2003.                                     hangman_found = ""
  2004.                                     for i in range(len(hangman_word)):
  2005.                                         if hangman_word[i] == letter:
  2006.                                             hangman_found += letter
  2007.                                         elif hangman_word[i] == " ":
  2008.                                             hangman_found += " "
  2009.                                         elif old_found[i] != "-":
  2010.                                             hangman_found += old_found[i]
  2011.                                         else:
  2012.                                             hangman_found += "-"
  2013.                                     hangman_guessed_letters = hangman_guessed_letters + " " + letter
  2014.                                     if hangman_found == hangman_word:
  2015.                                         yield from client.send_message(message.channel,  "<HMAN> You win! The word was: " + str( hangman_word) + " you got it in " + str(hangman_tries) + " tries!")
  2016.                                         hangman_word = ""
  2017.                                         hangman_found = ""
  2018.                                         hangman_guess = 0
  2019.                                         hangman_guessed_letters = ""
  2020.                                         hangman_tries = 0
  2021.                                     else:
  2022.                                         yield from client.send_message(message.channel, "<HMAN> Correct letter! Current progress: " + hangman_found + " with " + str(hangman_guess) + " (bad) guesses left. Wrong letters guessed: " + hangman_guessed_letters)
  2023.                                 else:
  2024.                                     hangman_guess -= 1
  2025.                                     hangman_guessed_letters = hangman_guessed_letters + " " + letter
  2026.                                     if hangman_guess <= 0:
  2027.                                         yield from client.send_message(message.channel, "<HMAN> Failed! The word was: " + str( hangman_word) + " you got " + str( hangman_found) + " in " + str(hangman_tries) + " tries!")
  2028.                                         hangman_word = ""
  2029.                                         hangman_found = ""
  2030.                                         hangman_guess = 0
  2031.                                         hangman_guessed_letters = ""
  2032.                                         hangman_tries = 0
  2033.                                     else:
  2034.                                         yield from client.send_message(message.channel, "<HMAN> Wrong letter! Current progress: " + hangman_found + " with " + str(hangman_guess) + " (bad) guesses left. Wrong letters guessed: " + hangman_guessed_letters)
  2035.                             else:
  2036.                                 yield from client.send_message(message.channel, "<HMAN> Whoops! " + str(
  2037.                                     letter) + " has already been guessed!")
  2038.                         else:
  2039.                             guess = params[0]
  2040.                             for i in range(1, len(params)):
  2041.                                 guess = guess + " " + params[i]
  2042.                             if guess.lower() == hangman_word:
  2043.                                 yield from client.send_message(message.channel, "<HMAN> You win! The word was: " + str(
  2044.                                     hangman_word) + " you got it in " + str(hangman_tries) + " tries!")
  2045.                                 hangman_word = ""
  2046.                                 hangman_found = ""
  2047.                                 hangman_guess = 0
  2048.                                 hangman_guessed_letters = ""
  2049.                                 hangman_tries = 0
  2050.                             else:
  2051.                                 hangman_guess -= 1
  2052.                                 if hangman_guess <= 0:
  2053.                                     yield from client.send_message(message.channel, "<HMAN> Failed! The word was: " + str(
  2054.                                         hangman_word) + " you got " + str(hangman_found) + " in " + str(
  2055.                                         hangman_tries) + " tries!")
  2056.                                     hangman_word = ""
  2057.                                     hangman_found = ""
  2058.                                     hangman_guess = 0
  2059.                                     hangman_guessed_letters = ""
  2060.                                     hangman_tries = 0
  2061.                                 else:
  2062.                                     yield from client.send_message(message.channel, "<HMAN> Wrong guess! Current progress: " + hangman_found + " with " + str(hangman_guess) + " (bad) guesses left. Wrong letters guessed: " + hangman_guessed_letters)
  2063.                 else:
  2064.                     yield from client.send_message(message.channel,
  2065.                                                    "<HMAN> Failed to use hangman, do it properly" + formatting)
  2066.                 sucess = True
  2067.             except():
  2068.                 yield from client.send_message(message.channel,
  2069.                                                "<HMAN> Failed to use hangman, do it properly" + formatting)
  2070.         elif is_command(message.content, "8ball"):
  2071.             if not check_command(message.author.name, "8ball"):
  2072.                 yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2073.             else:
  2074.                 msg = ball_8[random.randint(0, len(ball_8) - 1)]
  2075.                 yield from client.send_message(message.channel, "<8BALL> " + msg)
  2076.         elif is_command(message.content, "flip"):
  2077.             if not check_command(message.author.name, "flip"):
  2078.                 yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2079.             else:
  2080.                 msg = "<COIN> Head"
  2081.                 if (random.randint(0, 1) == 0):
  2082.                     msg = "<COIN> Tail"
  2083.                 yield from client.send_message(message.channel, msg)
  2084.         elif is_command(message.content, "roll"):
  2085.             if not check_command(message.author.name, "roll"):
  2086.                 yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2087.             else:
  2088.                 msg = "<DICE> " + str(random.randint(1, 6))
  2089.                 yield from client.send_message(message.channel, msg)
  2090.  
  2091.         elif is_command(message.content, "msg"):
  2092.             formatting = ": see "+cfix()+"msg help for usage"
  2093.             try:
  2094.                 params = [""]
  2095.                 if " " in message.content:
  2096.                     params = message.content[message.content.find(" ")+1:].split(" ")
  2097.                 if params[0] == "send":
  2098.                     if not check_command(message.author.name, "msg send", "msg"):
  2099.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2100.                     else:
  2101.                         formatting = ": "+cfix()+"msg send <user> <msg>"
  2102.                         if len(params) > 2:
  2103.                             name = get_name(params[1].lower()).lower()
  2104.                             if not message.channel.is_private:
  2105.                                 for mem in message.author.server.members:
  2106.                                     if name in mem.name.lower():
  2107.                                         name = mem.name.lower()
  2108.                                         break
  2109.                             msg = params[2]
  2110.                             for i in range(3, len(params)):
  2111.                                 msg = msg + " " + params[i]
  2112.                             leave_message(name, "[" + message.author.name + "] " + msg)
  2113.                             yield from client.send_message(message.author, "<MSG> left a message for " + name)
  2114.                             sucess = True
  2115.                         else:
  2116.                             raise (Exception())
  2117.                 elif params[0] == "help":
  2118.                     if not check_command(message.author.name, "msg help", "msg"):
  2119.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2120.                     else:
  2121.                         formatting = ": "+cfix()+"msg help"
  2122.                         page = 0
  2123.                         if len(params) > 1:
  2124.                             page = int(params[1]) - 1
  2125.                         lines = print_help(msg_help_str, page)
  2126.                         if lines is not None:
  2127.                             for line in lines:
  2128.                                 yield from client.send_message(message.author, line)
  2129.                             sucess = True
  2130.                         else:
  2131.                             yield from client.send_message(message.channel, "<MSG> invalid page!")
  2132.                 elif params[0] == "check":
  2133.                     if not check_command(message.author.name, "msg check", "msg"):
  2134.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2135.                     else:
  2136.                         formatting = ": "+cfix()+"msg check"
  2137.                         name = message.author.name.lower()
  2138.                         msgs = get_messages(name)
  2139.                         for i in range(len(msgs)):
  2140.                             msg = msgs[i]
  2141.                             yield from client.send_message(message.author, "<MSG> (" + str(i) + ") " + msg)
  2142.                         sucess = True
  2143.                 elif params[0] == "delete" or params[0] == "del":
  2144.                     if not check_command(message.author.name, "msg delete", "msg"):
  2145.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2146.                     else:
  2147.                         formatting = ": "+cfix()+"msg delete|del [number]"
  2148.                         if len(params) == 1:
  2149.                             name = message.author.name.lower()
  2150.                             if name in left_messages:
  2151.                                 del left_messages[name]
  2152.                             yield from client.send_message(message.author, "<MSG> deleted all messages")
  2153.                         else:
  2154.                             name = message.author.name.lower()
  2155.                             if name in left_messages:
  2156.                                 n = 0
  2157.                                 for i in range(1, len(params)):
  2158.                                     if ">" in params[i]:
  2159.                                         inds = params[i].split(">")
  2160.                                         for index in range(int(inds[0]), int(inds[1]) + 1):
  2161.                                             if index < len(left_messages[name]):
  2162.                                                 del left_messages[name][index - n]
  2163.                                                 n += 1
  2164.                                             else:
  2165.                                                 break
  2166.                                     else:
  2167.                                         index = int(params[i]) - n
  2168.                                         if index < len(left_messages[name]):
  2169.                                             del left_messages[name][index]
  2170.                                             n += 1
  2171.                             save_messages()
  2172.                             yield from client.send_message(message.author, "<MSG> deleted selected messages")
  2173.                         sucess = True
  2174.                 else:
  2175.                     raise(Exception())
  2176.             except:
  2177.                 yield from client.send_message(message.author, "<MSG> Failed to use msg" + formatting)
  2178.         elif is_command(message.content, "song"):
  2179.             params = [""]
  2180.             if " " \
  2181.                     in message.content:
  2182.                 params = message.content[message.content.find(" ")+1:].split(" ")
  2183.             formatting = ": see "+cfix()+"song help"
  2184.             try:
  2185.                 global song_queue, voice_chn, song_finished, current_music_player, song_paused, skip_votes, song_list, song_collection, song_volume
  2186.                 if params[0] == "add":
  2187.                     if not check_command(message.author.name, "song add", "song"):
  2188.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2189.                     else:
  2190.                         formatting = ": "+cfix()+"song add <playlist|songlink> [songlink]"
  2191.                         collection = "default"
  2192.                         songname = params[1]
  2193.                         if len(params) > 2:
  2194.                             collection = params[1]
  2195.                             songname = params[2]
  2196.                         if "youtube" in songname and "/watch" in songname:
  2197.                             add_song(collection, songname)
  2198.                             yield from client.send_message(message.channel, "<SONG> Added song to " + collection)
  2199.                             sucess = True
  2200.                         else:
  2201.                             yield from client.send_message(message.channel, "<SONG> Can only add youtube links!")
  2202.                 elif params[0] == "del" or params[0] == "delete":
  2203.                     if not check_command(message.author.name, "song delete", "song"):
  2204.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2205.                     else:
  2206.                         formatting = ": "+cfix()+"song del|delete <song|playlist> [song]"
  2207.                         collection = "default"
  2208.                         songname = params[1]
  2209.                         if len(params) > 2:
  2210.                             collection = params[1]
  2211.                             songname = params[2]
  2212.                         if remove_song(collection, songname):
  2213.                             yield from client.send_message(message.channel, "<SONG> removed song from " + collection)
  2214.                         else:
  2215.                             yield from client.send_message(message.channel, "<SONG> could not find that song in " + collection)
  2216.                         sucess = True
  2217.                 elif params[0] == "q" or params[0] == "queue":
  2218.                     if not check_command(message.author.name, "song queue", "song"):
  2219.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2220.                     else:
  2221.                         formatting = ": "+cfix()+"song q|queue <songlink>"
  2222.  
  2223.                         song_queue.append(params[1])
  2224.                         yield from client.send_message(message.channel, "<SONG> Queued song!")
  2225.                         sucess = True
  2226.                 elif params[0] == "playlists":
  2227.                     if not check_command(message.author.name, "song playlists", "song"):
  2228.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2229.                     else:
  2230.                             formatting = ": "+cfix()+"song playlists"
  2231.                             if len(collections) > 0:
  2232.                                 msg = collections[0]
  2233.                                 for i in range(1, len(collections)):
  2234.                                     msg = msg + ", " + collections[i]
  2235.                                 yield from client.send_message(message.channel, "<SONG> Playlists: " + msg)
  2236.                             else:
  2237.                                 yield from client.send_message(message.channel, "<SONG> Playlists: No collections :o")
  2238.                             sucess = True
  2239.                 elif params[0] == "help":
  2240.                     if not check_command(message.author.name, "song help", "song"):
  2241.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2242.                     else:
  2243.                         formatting = ": "+cfix()+"song help"
  2244.                         page = 0
  2245.                         if len(params) > 1:
  2246.                             page = int(params[1]) - 1
  2247.                         lines = print_help(song_help_str, page)
  2248.                         if lines is not None:
  2249.                             for line in lines: yield from client.send_message(message.author, line)
  2250.                             sucess = True
  2251.                         else:
  2252.                             yield from client.send_message(message.channel, "<SONG> invalid page!")
  2253.                 elif params[0] == "volume":
  2254.                     if not check_command(message.author.name, "song volume", "song"):
  2255.                          yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2256.                     else:
  2257.                         if current_music_player is not None:
  2258.                             song_volume = min(2, max(0, int(params[1]) / 100))
  2259.                             current_music_player.volume = song_volume
  2260.                             yield from client.send_message(message.channel, "<SONG> set volume to " + str(song_volume*100) + "%")
  2261.                         else:
  2262.                             yield from client.send_message(message.channel, "<SONG> Radio isn't currently on!")
  2263.                 elif params[0] == "radio":
  2264.                     if not check_command(message.author.name, "song radio", "song"):
  2265.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2266.                     else:
  2267.  
  2268.                         if voice_chn is None:
  2269.                             yield from client.send_message(message.channel,
  2270.                                                            "<SONG> cannot start radio when not voice-connected!")
  2271.                         else:
  2272.                             if radio_channel is None:
  2273.                                 for ch in message.author.server.channels:
  2274.                                     if ch.name.lower() == rchn():
  2275.                                         radio_channel = ch
  2276.                                         break
  2277.                             colls = ["default"]
  2278.                             if len(params) > 1:
  2279.                                 colls = params[1:]
  2280.                                 if params[1] == "all":
  2281.                                     colls = collections
  2282.                             str_colls = colls[0]
  2283.                             for i in range(1, len(colls)):
  2284.                                 str_colls = str_colls + ", " + colls[i]
  2285.                             if not song_finished:
  2286.                                 song_collection = colls
  2287.                                 sucess = True
  2288.                                 yield from client.send_message(message.channel, "<SONG> radio playlist changed to: " + str_colls)
  2289.                             else:
  2290.                                 yield from start_radio(colls)
  2291.                                 yield from client.send_message(message.channel,  "<SONG> radio started with playlist set to: " + str_colls)
  2292.                         sucess = True
  2293.                 elif params[0] == "link":
  2294.                     if not check_command(message.author.name, "song link", "song"):
  2295.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2296.                     else:
  2297.                         if current_music_player is not None:
  2298.                             yield from client.send_message(message.channel, "<SONG> Current song: " + current_music_player.url)
  2299.                         else:
  2300.                             yield from client.send_message(message.channel, "<SONG> Radio is not currently on!")
  2301.                 elif params[0] == "size":
  2302.                     if not check_command(message.author.name, "song size", "song"):
  2303.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2304.                     else:
  2305.                         colls = ["default"]
  2306.                         if len(params) > 1:
  2307.                             colls = params[1:]
  2308.                             if params[1] == "all":
  2309.                                 colls = collections
  2310.                         songlist = get_songlist(colls)
  2311.                         str_colls = colls[0]
  2312.                         for i in range(1, len(colls)):
  2313.                             str_colls = str_colls + ", " + colls[i]
  2314.                         yield from client.send_message(message.channel,
  2315.                                                        "<SONG> There are " + str(len(songlist)) + " songs in " + str_colls)
  2316.                         sucess = True
  2317.                 elif params[0] == "pause":
  2318.                     if not check_command(message.author.name, "song pause", "song"):
  2319.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2320.                     else:
  2321.  
  2322.                         if current_music_player is not None:
  2323.                             if not song_paused:
  2324.                                 current_music_player.pause()
  2325.                                 song_paused = True
  2326.                                 game = discord.Game()
  2327.                                 game.name = current_music_player.title
  2328.                                 yield from client.change_status(game, True)
  2329.                                 yield from client.send_message(message.channel, "<SONG> Radio paused!")
  2330.                             else:
  2331.                                 yield from client.send_message(message.channel,
  2332.                                                                "<SONG> Radio already paused! do !song resume to resume it")
  2333.                         else:
  2334.                             yield from client.send_message(message.channel, "<SONG> The radio isn't on!")
  2335.                 elif params[0] == "resume":
  2336.                     if not check_command(message.author.name, "song resume", "song"):
  2337.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2338.                     else:
  2339.  
  2340.                         if current_music_player is not None:
  2341.                             if song_paused:
  2342.                                 current_music_player.resume()
  2343.                                 song_paused = False
  2344.                                 game = discord.Game()
  2345.                                 game.name = current_music_player.title
  2346.                                 yield from client.change_status(game, False)
  2347.                                 yield from client.send_message(message.channel, "<SONG> Radio resumed!")
  2348.                             else:
  2349.                                 yield from client.send_message(message.channel,
  2350.                                                                "<SONG> Radio isn't paused! !song pause to pause it")
  2351.                         else:
  2352.                             yield from client.send_message(message.channel, "<SONG> The radio isn't on!")
  2353.                 elif params[0] == "skip":
  2354.                     if not check_command(message.author.name, "song skip", "song"):
  2355.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2356.                     else:
  2357.  
  2358.                         if voice_chn is not None:
  2359.                             members = voice_chn.channel.voice_members
  2360.                             result = False
  2361.                             for mem in members:
  2362.                                 if mem.name == message.author.name:
  2363.                                     result = True
  2364.                                     break
  2365.                             if result:
  2366.                                 req_votes = math.ceil(0.5 * (len(members) - 1))
  2367.                                 if message.author.name in skip_votes:
  2368.                                     yield from client.send_message(message.channel,
  2369.                                                                    "<SONG> You've already voted to skip! " + str(
  2370.                                                                        len(skip_votes)) + " out of " + str(
  2371.                                                                        req_votes) + " votes required to skip")
  2372.                                 else:
  2373.                                     skip_votes.append(message.author.name)
  2374.  
  2375.                                     if len(skip_votes) >= req_votes:
  2376.                                         current_music_player.stop()
  2377.                                         sucess = True
  2378.                                         yield from client.send_message(message.channel, "<SONG> Song skipped!")
  2379.                                     else:
  2380.                                         yield from client.send_message(message.channel,
  2381.                                                                        "<SONG> " + str(len(skip_votes)) + " out of " + str(
  2382.                                                                            req_votes) + " votes required to skip")
  2383.                             else:
  2384.                                 yield from client.send_message(message.channel,
  2385.                                                                "<SONG> Can only vote to skip if you're listening!")
  2386.                         else:
  2387.                             yield from client.send_message(message.channel, "<SONG> Radio is not currently on!")
  2388.                 elif params[0] == "connect":
  2389.                     if not check_command(message.author.name, "song connect", "song"):
  2390.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2391.                     else:
  2392.  
  2393.                         song_finished = True
  2394.                         if voice_chn is not None:
  2395.                             yield from voice_chn.disconnect()
  2396.                             voice_chn = None
  2397.                             current_music_player = None
  2398.                         name = params[1].lower()
  2399.                         joined = False
  2400.                         for channel in message.author.server.channels:
  2401.  
  2402.                             if name in channel.name.lower() and channel.type is discord.ChannelType.voice:
  2403.                                 voice_chn = yield from client.join_voice_channel(channel)
  2404.                                 yield from client.send_message(message.channel, "<SONG> joined channel " + channel.name)
  2405.                                 joined = True
  2406.                                 break
  2407.                         if not joined:
  2408.                             yield from client.send_message(message.channel, "<SONG> failed to join channel " + name)
  2409.                         sucess = True
  2410.                 elif params[0] == "stop":
  2411.                     if not check_command(message.author.name, "song stop", "song"):
  2412.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2413.                     else:
  2414.  
  2415.                         if current_music_player is not None:
  2416.                             if voice_chn is not None:
  2417.                                 yield from voice_chn.disconnect()
  2418.                             song_paused = False
  2419.                             song_queue = []
  2420.                             current_music_player.stop()
  2421.                             voice_chn = None
  2422.                             current_music_player = None
  2423.                             song_list = []
  2424.                             yield from client.send_message(message.channel, "<SONG> radio stopped")
  2425.                         else:
  2426.                             yield from client.send_message(message.channel, "<SONG> radio not playing!")
  2427.                         sucess = True
  2428.                 elif params[0] == '':
  2429.                     if not check_command(message.author.name, "song random", "song"):
  2430.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2431.                     else:
  2432.                         formatting = ": "+cfix()+"song"
  2433.                         songname = get_song(["default"])
  2434.                         if songname is not None:
  2435.                             yield from client.send_message(message.channel, songname)
  2436.                             sucess = True
  2437.                         else:
  2438.                             yield from client.send_message(message.channel, "<SONG> Failed to find a song in default?")
  2439.                 else:
  2440.                     if not check_command(message.author.name, "song random", "song"):
  2441.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2442.                     else:
  2443.                         formatting = ": "+cfix()+"song [playlists]"
  2444.                         colls = params
  2445.                         if params[0] == "all":
  2446.                             colls = collections
  2447.                         songname = get_song(colls)
  2448.                         if songname is not None:
  2449.                             yield from client.send_message(message.channel, get_song(colls))
  2450.                             sucess = True
  2451.                         else:
  2452.                             yield from client.send_message(message.channel,
  2453.                                                            "<SONG> Failed to find song, you sure those playlists exist?")
  2454.             except:
  2455.                 yield from client.send_message(message.channel, "<SONG> Failed, do it properly" + formatting)
  2456.         elif is_command(message.content, "rng"):
  2457.             params = [""]
  2458.             if " " in message.content:
  2459.                 params = message.content[message.content.find(" ")+1:].split(" ")
  2460.             formatting = ": see "+cfix()+"rng help"
  2461.             try:
  2462.                 if len(params) == 1 and params[0] == '':
  2463.                     if not check_command(message.author.name, "rng"):
  2464.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2465.                     else:
  2466.                         yield from client.send_message(message.channel, "<RNG> " + str(random.random()))
  2467.                         sucess = True
  2468.                 elif params[0] == "help":
  2469.                     if not check_command(message.author.name, "rng help", "rng"):
  2470.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2471.                     else:
  2472.                         page = 0
  2473.                         if len(params) > 1:
  2474.                             page = int(params[1]) - 1
  2475.                         lines = print_help(rng_help_str, page)
  2476.                         if lines is not None:
  2477.                             for line in lines: yield from client.send_message(message.author, line)
  2478.                             sucess = True
  2479.                         else:
  2480.                             yield from client.send_message(message.channel, "<RNG> invalid page!")
  2481.                 elif len(params) == 1:
  2482.                     if not check_command(message.author.name, "rng"):
  2483.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2484.                     else:
  2485.                             formatting = ": "+cfix()+"rng <number>"
  2486.                             yield from client.send_message(message.channel,
  2487.                                                            "<RNG> " + str(int(float(params[0]) * random.random())))
  2488.                             sucess = True
  2489.                 elif len(params) == 2:
  2490.                     if not check_command(message.author.name, "rng"):
  2491.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2492.                     else:
  2493.                         formatting = ": "+cfix()+"rng <lower> <upper> | "+cfix()+"rng <f|number> <f|number>"
  2494.                         if params[0] == 'f' or params[0] == 'real':
  2495.                             formatting = ": "+cfix()+"rng f <number>"
  2496.                             yield from client.send_message(message.channel,
  2497.                                                            "<RNG> " + str(float(params[1]) * random.random()))
  2498.                             sucess = True
  2499.                         elif params[1] == 'f' or params[1] == 'real':
  2500.                             formatting = ": "+cfix()+"rng <number> f"
  2501.                             yield from client.send_message(message.channel,
  2502.                                                            "<RNG> " + str(float(params[0]) * random.random()))
  2503.                             sucess = True
  2504.                         else:
  2505.                             formatting = ": "+cfix()+"rng <lower> <upper>"
  2506.                             rng = int(float(params[0]) + ((float(params[1]) - float(params[0])) * random.random()))
  2507.                             yield from client.send_message(message.channel, "<RNG> " + str(rng))
  2508.                             sucess = True
  2509.                 elif len(params) == 3:
  2510.                     if not check_command(message.author.name, "rng"):
  2511.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2512.                     else:
  2513.                         formatting = ": "+cfix()+"rng <f|lower> <f|lower|upper> <f|upper>"
  2514.                         if (params[0] == 'f' or params[0] == 'real'):
  2515.                             formatting = ": "+cfix()+"rng f <lower> <upper>"
  2516.                             rng = float(params[1]) + ((float(params[2]) - float(params[1])) * random.random())
  2517.                             yield from client.send_message(message.channel, "<RNG> " + str(rng))
  2518.                             sucess = True
  2519.                         elif (params[1] == 'f' or params[1] == 'real'):
  2520.                             formatting = ": "+cfix()+"rng <lower> f <upper>"
  2521.                             rng = float(params[0]) + ((float(params[2]) - float(params[0])) * random.random())
  2522.                             yield from client.send_message(message.channel, "<RNG> " + str(rng))
  2523.                             sucess = True
  2524.                         elif (params[2] == 'f' or params[2] == 'real'):
  2525.                             formatting = ": "+cfix()+"rng <lower> <upper> f"
  2526.                             rng = float(params[0]) + ((float(params[1]) - float(params[0])) * random.random())
  2527.                             yield from client.send_message(message.channel, "<RNG> " + str(rng))
  2528.                             sucess = True
  2529.                 else:
  2530.                     yield from client.send_message(message.channel, "<RNG> Failed, see "+cfix()+"rng help")
  2531.             except:
  2532.                 yield from client.send_message(message.channel, "<RNG> Failed, do it properly" + formatting)
  2533.         elif is_command(message.content, "code"):
  2534.             if not check_command(message.author.name, "code"):
  2535.                 yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2536.             else:
  2537.                 yield from client.send_message(message.channel, "<CODE> " + yoyo_code_link)
  2538.         elif is_command(message.content, "nick"):
  2539.             try:
  2540.                 params = [""]
  2541.                 if " " in message.content:
  2542.                     params = message.content[message.content.find(" ")+1:].split(" ")
  2543.                 if len(params) == 2:
  2544.                     if not check_command(message.author.name, "nick set other", "nick"):
  2545.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2546.                     else:
  2547.                         name = get_name(params[0])
  2548.                         if name == params[0]:
  2549.                             for mem in message.author.server.members:
  2550.                                 if name in mem.name.lower():
  2551.                                     name = mem.name
  2552.                                     break
  2553.                         add_nick(name, params[1])
  2554.                         yield from client.send_message(message.channel,
  2555.                                                        "<NICK> set " + name + "'s nickname to " + params[1])
  2556.                         sucess = True
  2557.                 elif len(params) == 1:
  2558.                     if not check_command(message.author.name, "nick set", "nick"):
  2559.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2560.                     else:
  2561.                         name = message.author.name
  2562.                         add_nick(name, params[0])
  2563.                         yield from client.send_message(message.channel,
  2564.                                                        "<NICK> set " + name + "'s nickname to " + params[0])
  2565.                         sucess = True
  2566.                 else:
  2567.                     raise(Exception())
  2568.             except:
  2569.                 yield from client.send_message(message.channel, "<NICK> Failed to assign nickname")
  2570.         elif is_command(message.content, "decide"):
  2571.             try:
  2572.                 if not check_command(message.author.name, "decide"):
  2573.                     yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2574.                 else:
  2575.                     decisions = message.content[8:].split(" or ")
  2576.                     yield from client.send_message(message.channel, decisions[random.randint(0, len(decisions) - 1)] + ".")
  2577.                     sucess = True
  2578.             except:
  2579.                 yield from client.send_message(message.channel,
  2580.                                                "<DECIDE> Failed, do "+cfix()+"decide <decision> or <decision> [or ...]")
  2581.         elif is_command(message.content, "nickname"):
  2582.             params = [""]
  2583.             if " " in message.content:
  2584.                 params = message.content[message.content.find(" ")+1:].split(" ")
  2585.             if len(params[0]) == 0:
  2586.                 if not check_command(message.author.name, "nickname me", "nickname"):
  2587.                     yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2588.                 else:
  2589.                     name = message.author.name.lower()
  2590.                     if name in nick_players:
  2591.                         yield from client.send_message(message.channel,
  2592.                                                        "<NICK> " + name + "'s current nickname: " + nicknames[name])
  2593.                     else:
  2594.                         yield from client.send_message(message.channel, "<NICK> " + name + " has no current nickname!")
  2595.                 sucess = True
  2596.             else:
  2597.                 if not check_command(message.author.name, "nickname other", "nickname"):
  2598.                     yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2599.                 else:
  2600.                     name = get_name(params[0])
  2601.                     if name == params[0].lower():
  2602.                         for mem in message.channel.server.members:
  2603.                             if name in mem.name.lower():
  2604.                                 name = mem.name.lower()
  2605.                                 break
  2606.                     print(name)
  2607.                     if name in nick_players:
  2608.                         yield from client.send_message(message.channel,
  2609.                                                        "<NICK> " + name + "'s current nickname: " + nicknames[name])
  2610.                     else:
  2611.                         yield from client.send_message(message.channel, "<NICK> " + name + " has no current nickname!")
  2612.                 sucess = True
  2613.         elif is_command(message.content, "hb"):
  2614.             try:
  2615.                 if not check_command(message.author.name, "hb"):
  2616.                     yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2617.                 else:
  2618.                     suffix = ""
  2619.                     if " " in message.content:
  2620.                         index = message.content.find(" ")
  2621.                         suffix = message.content[index + 1:].replace(" ", "-")
  2622.                     print(suffix)
  2623.                     yield from client.send_message(message.channel, get_humblebundle(suffix))
  2624.                     sucess = True
  2625.             except:
  2626.                 yield from client.send_message(message.channel, "<HUMBLE> couldn't find the current bundle!")
  2627.         elif is_command(message.content, "xkcd"):
  2628.             try:
  2629.                 if not check_command(message.author.name, "xkcd"):
  2630.                     yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2631.                 else:
  2632.                     number = 0
  2633.                     params = [""]
  2634.                     if " " in message.content:
  2635.                         params = message.content[message.content.find(" ")+1:].split(" ")
  2636.                     if params[0] == "":
  2637.                         number = random.randint(xkcd_range[0], xkcd_range[1])
  2638.                     else:
  2639.                         number = int(params[0])
  2640.                     link = get_xkcd_link(number)
  2641.                     if link is not None:
  2642.                         yield from client.send_message(message.channel, link)
  2643.                         sucess = True
  2644.                     else:
  2645.                         yield from client.send_message(message.channel, "<XKCD> Couldn't find that comic!")
  2646.             except:
  2647.                 yield from client.send_message(message.channel, "<XKCD> failed! use "+cfix()+"xkcd [comic-number]")
  2648.         elif is_command(message.content, "cah"):
  2649.             try:
  2650.                 if not check_command(message.author.name, "cah"):
  2651.                     yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2652.                 else:
  2653.                     number = 0
  2654.                     params = [""]
  2655.                     if " " in message.content:
  2656.                         params = message.content[message.content.find(" ")+1:].split(" ")
  2657.                     if params[0] == "":
  2658.                         number = random.randint(cah_range[0], cah_range[1])
  2659.                     else:
  2660.                         number = int(params[0])
  2661.                     link = get_cah_link(number)
  2662.                     if link is not None:
  2663.                         yield from client.send_message(message.channel, link)
  2664.                         sucess = True
  2665.                     else:
  2666.                         yield from client.send_message(message.channel, "<C&H> Couldn't find that comic!")
  2667.             except:
  2668.                 yield from client.send_message(message.channel, "<C&H> failed! use "+cfix()+"cah [comic-number]")
  2669.         elif is_command(message.content, "img"):
  2670.             try:
  2671.                 if not check_command(message.author.name, "img"):
  2672.                     yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2673.                 else:
  2674.                     number = -1
  2675.                     params = [""]
  2676.                     if " " in message.content:
  2677.                         params = message.content[message.content.find(" ")+1:].split(" ")
  2678.                     if params[0] != "":
  2679.                         number = int(params[0])
  2680.                     link = get_metapic(number)
  2681.                     if link is not None:
  2682.                         yield from client.send_message(message.channel, link)
  2683.                         sucess = True
  2684.                     else:
  2685.                         yield from client.send_message(message.channel, "<IMG> Couldn't find that image!")
  2686.             except:
  2687.                 yield from client.send_message(message.channel, "<IMG> couldn't find an image")
  2688.         elif is_command(message.content, "poke"):
  2689.             try:
  2690.                 if not check_command(message.author.name, "poke"):
  2691.                     yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2692.                 else:
  2693.                     params = [""]
  2694.                     if " " in message.content:
  2695.                         params = message.content[message.content.find(" ")+1:].split(" ")
  2696.                     if len(params) == 1 and params[0] != '':
  2697.                         name = get_name(params[0].lower()).lower()
  2698.                         member = None
  2699.                         for mem in message.author.server.members:
  2700.                             if name in mem.name.lower():
  2701.                                 member = mem
  2702.                                 break
  2703.  
  2704.                         if member is not None:
  2705.                             name = member.name
  2706.                             if (name != "yoyobot"):
  2707.                                 if (name in poke_cooldowns):
  2708.                                     if poke_cooldowns[name] < time.clock():
  2709.                                         del poke_cooldowns[name]
  2710.                                 if (name not in poke_cooldowns):
  2711.                                     yield from client.send_message(member, "POKE!!!")
  2712.                                     sucess = True
  2713.                                     poke_cooldowns[name] = 60 + time.clock()
  2714.                                 else:
  2715.                                     yield from client.send_message(message.channel,
  2716.                                                                    "<POKE> don't try to poke them too many times...")
  2717.                             else:
  2718.                                 yield from client.send_message(message.channel, "<POKE> I'm not going to poke myself...")
  2719.  
  2720.                         else:
  2721.                             raise (Exception("poke", "user doesn't exist"))
  2722.  
  2723.             except:
  2724.                 yield from client.send_message(message.channel, "<POKE> Whoops, you sure that user exists?")
  2725.         elif is_command(message.content, "help"):
  2726.             try:
  2727.                 if not check_command(message.author.name, "help"):
  2728.                     yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2729.                 else:
  2730.                     params = [""]
  2731.                     if " " in message.content:
  2732.                         params = message.content[message.content.find(" ")+1:].split(" ")
  2733.                     page = 0
  2734.                     if params[0] != "":
  2735.                         page = int(params[0]) - 1
  2736.                     lines = print_help(help_str, page)
  2737.                     if lines is not None:
  2738.                         for line in lines: yield from client.send_message(message.author, line)
  2739.                         sucess = True
  2740.                     else:
  2741.                         yield from client.send_message(message.channel, "<HELP> invalid page!")
  2742.             except():
  2743.                 yield from client.send_message(message.channel, "<HELP> you managed to break the help page.. how..")
  2744.         elif is_command(message.content, "status"):
  2745.             try:
  2746.                 if not check_command(message.author.name, "status"):
  2747.                     yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2748.                 else:
  2749.                     params = [""]
  2750.                     if " " in message.content:
  2751.                         params = message.content[message.content.find(" ")+1:].split(" ")
  2752.                     idle = False
  2753.                     if len(params) > 1:
  2754.                         if params[1].lower() == "true" or params[1].lower() == "on":
  2755.                             idle = True
  2756.                     game = discord.Game()
  2757.                     game.name = params[0]
  2758.                     yield from client.change_status(game, idle)
  2759.                     sucess = True
  2760.             except:
  2761.                 print("status update not working properly...")
  2762.         elif is_command(message.content, "invite"):
  2763.             if not check_command(message.author.name, "invite"):
  2764.                 yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2765.             else:
  2766.                 inv = yield from client.create_invite(message.author.server, max_age=600)
  2767.                 yield from client.send_message(message.channel, inv.url)
  2768.         elif is_command(message.content, "uptime"):
  2769.             if not check_command(message.author.name, "uptime"):
  2770.                 yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2771.             else:
  2772.                 global uptime_cooldown, uptime_start
  2773.                 secs = int(time.clock())
  2774.                 if secs > uptime_cooldown:
  2775.                     uptime_cooldown = secs + 30
  2776.                     cdat = create_current_dat()
  2777.                     elap = cdat.minus(uptime_start)
  2778.                     yield from client.send_message(message.channel, "I've been alive for " + elap.clever_format())
  2779.         elif is_command(message.content, "money"):
  2780.             formatting = ": see "+cfix()+"money help"
  2781.             try:
  2782.                 params = [""]
  2783.                 if " " in message.content:
  2784.                     params = message.content[message.content.find(" ")+1:].split(" ")
  2785.                 if params[0] == "set":
  2786.                     formatting = ": "+cfix()+"money set <username> <amount>"
  2787.                     if not check_command(message.author.name, "money set", "money"):
  2788.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2789.                     else:
  2790.                         name = get_name(params[1].lower()).lower()
  2791.                         found = False
  2792.                         for mem in message.author.server.members:
  2793.                             if name in mem.name.lower():
  2794.                                 name = mem.name
  2795.                                 found = True
  2796.                                 break
  2797.                         for user in user_money.keys():
  2798.                             if name in user.lower():
  2799.                                 name = user
  2800.                                 found = True
  2801.                                 break
  2802.                         if found or name in user_money:
  2803.                             amount = int(params[2])
  2804.                             set_money(name, amount)
  2805.                             yield from client.send_message(message.channel, "<$$$> Set " + name + "'s balance to $" + str(amount))
  2806.                         else:
  2807.                             yield from client.send_message(message.channel, "<$$$> Couldn't find user " + name)
  2808.                         sucess = True
  2809.                 elif params[0] == "give":
  2810.                     formatting = ": "+cfix()+"money give <username> <amount>"
  2811.                     if not check_command(message.author.name, "money give", "money"):
  2812.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2813.                     else:
  2814.                         name = get_name(params[1].lower()).lower()
  2815.                         found = False
  2816.                         for mem in message.author.server.members:
  2817.                             if name in mem.name.lower():
  2818.                                 name = mem.name
  2819.                                 found = True
  2820.                                 break
  2821.                         for user in user_money.keys():
  2822.                             if name in user.lower():
  2823.                                 name = user
  2824.                                 found = True
  2825.                                 break
  2826.                         if found or name in user_money:
  2827.                             amount = int(params[2])
  2828.                             balance = give_money(name, amount)
  2829.                             yield from client.send_message(message.channel, "<$$$> Gave $" + str(amount) + " to " + name + " (balance: $" + str(balance)+")")
  2830.                         else:
  2831.                             yield from client.send_message(message.channel, "<$$$> Couldn't find user " + name)
  2832.                         sucess = True
  2833.                 elif params[0] == "trade":
  2834.                     formatting = ": "+cfix()+"money trade <username> <amount>"
  2835.                     if not check_command(message.author.name, "money trade", "money"):
  2836.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2837.                     else:
  2838.                         name = get_name(params[1].lower()).lower()
  2839.                         found = False
  2840.                         for mem in message.author.server.members:
  2841.                             if name in mem.name.lower():
  2842.                                 name = mem.name
  2843.                                 found = True
  2844.                                 break
  2845.                         for user in user_money.keys():
  2846.                             if name in user.lower():
  2847.                                 name = user
  2848.                                 found = True
  2849.                                 break
  2850.                         if found or name in user_money:
  2851.                             amount = int(params[2])
  2852.                             if trade_money(message.author.name, name, amount):
  2853.                                 yield from client.send_message(message.channel, "<$$$> " + message.author.name + " traded $" + str(amount) + " to " + name + "(your balance: $" + str(get_money(message.author.name))+")")
  2854.                             else:
  2855.                                 yield from client.send_message(message.channel, "<$$$> You don't have enough money! Your balance: $" + str(get_money(message.author.name)))
  2856.                         else:
  2857.                             yield from client.send_message(message.channel, "<$$$> Couldn't find user " + name)
  2858.                         sucess = True
  2859.                 elif params[0] == "help":
  2860.                     if not check_command(message.author.name, "money help", "money"):
  2861.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2862.                     else:
  2863.                         page = 0
  2864.                         if len(params) > 1:
  2865.                             page = int(params[1]) - 1
  2866.                         lines = print_help(money_help_str, page)
  2867.                         if lines is not None:
  2868.                             for line in lines: yield from client.send_message(message.author, line)
  2869.                             sucess = True
  2870.                         else:
  2871.                             yield from client.send_message(message.channel, "<$$$> invalid page!")
  2872.                 elif params[0] == "":
  2873.                     formatting = ": "+cfix()+"money [username]"
  2874.                     if not check_command(message.author.name, "money check", "money"):
  2875.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2876.                     else:
  2877.                         yield from client.send_message(message.channel, "<$$$> Your balance is: $" + str(get_money(message.author.name)))
  2878.                     sucess = True
  2879.                 else:
  2880.                     formatting = ": "+cfix()+"money [username]"
  2881.                     if not check_command(message.author.name, "money check", "money"):
  2882.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2883.                     else:
  2884.                         name = params[0].lower()
  2885.                         found = False
  2886.                         for mem in message.author.server.members:
  2887.                             if name in mem.name.lower():
  2888.                                 name = mem.name
  2889.                                 found = True
  2890.                                 break
  2891.                         for user in user_money.keys():
  2892.                             if name in user.lower():
  2893.                                 name = user
  2894.                                 found = True
  2895.                                 break
  2896.                         if found or name in user_money:
  2897.                             yield from client.send_message(message.channel, "<$$$> "+ name + "'s balance is: $" + str(get_money(name)))
  2898.                         else:
  2899.                             yield from client.send_message(message.channel, "<$$$> Couldn't find user " + name)
  2900.                     sucess = True
  2901.             except:
  2902.                 yield from client.send_message(message.channel, "<$$$> Failed" + formatting)
  2903.         elif is_command(message.content, "reward"):
  2904.             formatting = ": see "+cfix()+"reward help"
  2905.             try:
  2906.                 params = [""]
  2907.                 if " " in message.content:
  2908.                     params = message.content[message.content.find(" ")+1:].split(" ")
  2909.                 if params[0] == "set":
  2910.                     formatting = ": "+cfix()+"reward set <reward> <commands>"
  2911.                     if not check_command(message.author.name, "reward set", "reward"):
  2912.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2913.                     else:
  2914.                         cmds = " ".join(params[2:]).split("||")
  2915.                         print(cmds)
  2916.                         set_reward(params[1], cmds)
  2917.                         yield from client.send_message(message.channel, "<RWD> Set " + params[1] + "'s reward commands.")
  2918.                         sucess = True
  2919.                 elif params[0] == "edit":
  2920.                     formatting = ": "+cfix()+"reward edit <reward> <commands>"
  2921.                     if not check_command(message.author.name, "reward edit", "reward"):
  2922.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2923.                     else:
  2924.                         cmds = []
  2925.                         remove = False
  2926.                         if params[2].lower() == "remove":
  2927.                             remove = True
  2928.                             cmds = params[3:]
  2929.                         else:
  2930.                             cmds = params[2:]
  2931.                         if edit_reward(params[1], cmds, remove):
  2932.                             yield from client.send_message(message.channel, "<RWD> Edited reward: " + params[1])
  2933.                         else:
  2934.                             yield from client.send_message(message.channel, "<RWD> Couldn't find a reward named: " + params[1])
  2935.                 elif params[0] == "delete" or params[0] == "del":
  2936.                     formatting = ": "+cfix()+"reward del|delete <reward>"
  2937.                     if not check_command(message.author.name, "reward delete", "reward"):
  2938.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2939.                     else:
  2940.                         if remove_reward(params[1]):
  2941.                             yield from client.send_message(message.channel, "<RWD> Deleted reward: " + params[1])
  2942.                         else:
  2943.                             yield from client.send_message(message.channel, "<RWD> Couldn't find a reward named: " + params[1])
  2944.                 elif params[0] == "get":
  2945.                     formatting = ": "+cfix()+"reward get <reward>"
  2946.                     if not check_command(message.author.name, "reward get", "reward"):
  2947.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2948.                     else:
  2949.                         result = get_reward(params[1])
  2950.                         if result is not None:
  2951.                             yield from client.send_message(message.channel, "<RWD> " + params[1] + "'s commands: \n" + "    \n".join(result))
  2952.                         else:
  2953.                             yield from client.send_message(message.channel, "<RWD> Couldn't find a reward named: " + params[1])
  2954.                 elif params[0] == "give":
  2955.                     formatting = ": "+cfix()+"reward give <username> <reward>"
  2956.                     if not check_command(message.author.name, "reward give", "reward"):
  2957.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2958.                     else:
  2959.                         name = get_name(params[1].lower()).lower()
  2960.                         member = None
  2961.                         for mem in message.author.server.members:
  2962.                             if name in mem.name.lower():
  2963.                                 member = mem
  2964.                                 break
  2965.                         if member is not None:
  2966.                             result = get_reward(params[2])
  2967.                             if result is not None:
  2968.                                 yield from use_reward(member, message.channel, result)
  2969.                             else:
  2970.                                 yield from client.send_message(message.channel, "<RWD> Couldn't find a reward named: " + params[1])
  2971.                         else:
  2972.                             yield from client.send_message(message.channel, "<RWD> Couldn't find a member named " + name + ", are you sure they're online?")
  2973.                 elif params[0] == "help":
  2974.                     formatting = ": "+cfix()+"reward help [page]"
  2975.                     if not check_command(message.author.name, "reward help", "reward"):
  2976.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2977.                     else:
  2978.                         page = 0
  2979.                         if len(params) > 1:
  2980.                             page = int(params[1]) - 1
  2981.                         lines = print_help(reward_help_str, page)
  2982.                         if lines is not None:
  2983.                             for line in lines: yield from client.send_message(message.author, line)
  2984.                             sucess = True
  2985.                         else:
  2986.                             yield from client.send_message(message.channel, "<RWD> invalid page!")
  2987.                 elif is_command(settings["command_prefix"] + params[0], "shop"):
  2988.                     if params[1] == "add":
  2989.                         formatting = ": "+cfix()+"reward shop add <reward> <price> <category> <name> <short description> "
  2990.                         if not check_command(message.author.name, "reward shop add", "reward shop"):
  2991.                             yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  2992.                         else:
  2993.                             item = ShopItem(params[2], int(params[3]), params[5], params[6], [params[6]])
  2994.                             add_item(params[4], item)
  2995.                             print("saving..")
  2996.                             save_shop()
  2997.                             print("saved")
  2998.                             yield from client.send_message(message.channel, "<ROLE> added item " + params[5] + " to " + params[4])
  2999.                     elif params[1] == "remove":
  3000.                         formatting = ": "+cfix()+"reward shop remove <category> [name]"
  3001.                         if not check_command(message.author.name, "reward shop remove", "reward shop"):
  3002.                             yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3003.                         else:
  3004.                             catname = params[2]
  3005.                             if catname in money_shop:
  3006.                                 if len(params) == 3:
  3007.                                     del money_shop[catname]
  3008.                                     save_shop()
  3009.                                     yield from client.send_message(message.channel, "<SHOP> Removed " + catname + " from the shop")
  3010.                                 else:
  3011.                                     if money_shop[catname].remove_item(params[3]):
  3012.                                         save_shop()
  3013.                                         yield from client.send_message(message.channel, "<SHOP> Removed " + params[3] + " from the " + catname)
  3014.                                     else:
  3015.                                         yield from client.send_message(message.channel, "<SHOP> Couldn't find an " + params[3] + " in " + catname)
  3016.                             else:
  3017.                                  yield from client.send_message(message.channel, "<SHOP> Couldn't find a category named " + catname)
  3018.                         sucess = True
  3019.                     elif params[1] == "price":
  3020.                         formatting = ": "+cfix()+"reward shop price <category> <name> <price>"
  3021.                         if not check_command(message.author.name, "reward shop price", "reward shop"):
  3022.                             yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3023.                         else:
  3024.                             catname = params[2]
  3025.                             if catname in money_shop:
  3026.                                 itemname = params[3]
  3027.                                 if money_shop[catname].set_price(itemname, int(params[4])):
  3028.                                     save_shop()
  3029.                                     yield from client.send_message(message.channel, "<SHOP> Set " + itemname + "'s price to $" + params[4])
  3030.                                 else:
  3031.                                     yield from client.send_message(message.channel, "<SHOP> Couldn't find an " + itemname + " in " + catname)
  3032.                             else:
  3033.                                 yield from client.send_message(message.channel, "<SHOP> Couldn't find a category named " + catname)
  3034.                             sucess = True
  3035.                     elif params[1] == "move":
  3036.                         formatting = ": "+cfix()+"reward shop move <name> <old_category> <new_category>"
  3037.                         if not check_command(message.author.name, "reward shop move", "reward shop"):
  3038.                             yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3039.                         else:
  3040.                             catname1 = params[3]
  3041.                             if catname1 in money_shop:
  3042.                                 catname2 = params[4]
  3043.                                 if catname2 in money_shop:
  3044.                                     itemname = params[2]
  3045.                                     if money_shop[catname1].move_item(itemname, money_shop[catname2]):
  3046.                                         save_shop()
  3047.                                         yield from client.send_message(message.channel, "<SHOP> Moved " + itemname + " from " + catname1 + " to " + catname2)
  3048.                                     else:
  3049.                                         yield from client.send_message(message.channel, "<SHOP> Couldn't find an " + itemname + " in " + catname1)
  3050.                                 else:
  3051.                                     yield from client.send_message(message.channel, "<SHOP> Couldn't find a category named " + catname2)
  3052.                             else:
  3053.                                 yield from client.send_message(message.channel, "<SHOP> Couldn't find a category named " + catname1)
  3054.                             sucess = True
  3055.                     elif params[1] == "hide":
  3056.                         formatting = ": "+cfix()+"reward shop hide <true|false> <category> [name]"
  3057.                         if not check_command(message.author.name, "reward shop hide", "reward shop"):
  3058.                             yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3059.                         else:
  3060.                             hidden = False
  3061.                             if params[2].lower() == "true":
  3062.                                 hidden = True
  3063.                             elif params[2].lower() != "false":
  3064.                                 raise(Exception())
  3065.                             catname = params[3]
  3066.                             if catname in money_shop:
  3067.                                 if len(params) == 4:
  3068.                                     money_shop[catname].set_hidden(hidden)
  3069.                                     save_shop()
  3070.                                     yield from client.send_message(message.channel, "<SHOP> Set " + catname + "'s hidden status to " + hidden)
  3071.                                 else:
  3072.                                     itemname = params[4]
  3073.                                     if money_shop[catname].set_hidden(hidden, itemname):
  3074.                                         save_shop()
  3075.                                         yield from client.send_message(message.channel, "<SHOP> Set " + itemname + "'s hidden status to " + str(hidden))
  3076.                                     else:
  3077.                                         yield from client.send_message(message.channel, "<SHOP> Couldn't find an " + itemname + " in " + catname)
  3078.                             else:
  3079.                                 yield from client.send_message(message.channel, "<SHOP> Couldn't find a category named " + catname)
  3080.                         sucess = True
  3081.                     elif params[1] == "short":
  3082.                         formatting = ": "+cfix()+"reward shop short <category> <name> <short description>"
  3083.                         if not check_command(message.author.name, "reward shop short", "reward shop"):
  3084.                             yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3085.                         else:
  3086.                             catname = params[2]
  3087.                             if catname in money_shop:
  3088.                                 itemname = params[3]
  3089.                                 if money_shop[catname].set_short(itemname, params[4]):
  3090.                                     save_shop()
  3091.                                     yield from client.send_message(message.channel, "<SHOP> Set " + itemname + "'s short description!")
  3092.                                 else:
  3093.                                     yield from client.send_message(message.channel, "<SHOP> Couldn't find an " + itemname + " in " + catname)
  3094.                             else:
  3095.                                 yield from client.send_message(message.channel, "<SHOP> Couldn't find a category named " + catname)
  3096.                             sucess = True
  3097.                     elif params[1] == "long":
  3098.                         formatting = ": "+cfix()+"reward shop long <category> <name> <long description>"
  3099.                         if not check_command(message.author.name, "reward shop long", "reward shop"):
  3100.                             yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3101.                         else:
  3102.                             if params[2] == "add":
  3103.                                 formatting = ": "+cfix()+"reward shop long add <category> <name> <long description>"
  3104.                                 catname = params[3]
  3105.                                 if catname in money_shop:
  3106.                                     itemname = params[4]
  3107.                                     if money_shop[catname].add_long(itemname, params[5]):
  3108.                                         save_shop()
  3109.                                         yield from client.send_message(message.channel, "<SHOP> Added to " + itemname + "'s long description!")
  3110.                                     else:
  3111.                                         yield from client.send_message(message.channel, "<SHOP> Couldn't find an " + itemname + " in " + catname)
  3112.                                 else:
  3113.                                     yield from client.send_message(message.channel, "<SHOP> Couldn't find a category named " + catname)
  3114.                                 sucess = True
  3115.                             elif params[2] == "del":
  3116.                                 formatting = ": "+cfix()+"reward shop long delete|del <category> <name> [line number]"
  3117.                                 catname = params[3]
  3118.                                 if catname in money_shop:
  3119.                                     itemname = params[4]
  3120.                                     line_number = -1
  3121.                                     if len(params) > 5:
  3122.                                         line_number = int(params[5])
  3123.                                     if money_shop[catname].remove_long(itemname, line_number):
  3124.                                         save_shop()
  3125.                                         linestr = "last line"
  3126.                                         if line_number != -1:
  3127.                                             linestr = "line " + str(line_number)
  3128.                                         yield from client.send_message(message.channel, "<SHOP> Removed " + linestr + " from " + itemname + "'s long description!")
  3129.                                     else:
  3130.                                         yield from client.send_message(message.channel, "<SHOP> Couldn't find an " + itemname + " in " + catname)
  3131.                                 else:
  3132.                                     yield from client.send_message(message.channel, "<SHOP> Couldn't find a category named " + catname)
  3133.                                 sucess = True
  3134.                             else:
  3135.                                 formatting = ": "+cfix()+"reward shop long <category> <name> <long description>"
  3136.                                 catname = params[2]
  3137.                                 if catname in money_shop:
  3138.                                     itemname = params[3]
  3139.                                     if money_shop[catname].set_long(itemname, params[4]):
  3140.                                         save_shop()
  3141.                                         yield from client.send_message(message.channel, "<SHOP> Reset " + itemname + "'s long description!")
  3142.                                     else:
  3143.                                         yield from client.send_message(message.channel, "<SHOP> Couldn't find an " + itemname + " in " + catname)
  3144.                                 else:
  3145.                                     yield from client.send_message(message.channel, "<SHOP> Couldn't find a category named " + catname)
  3146.                                 sucess = True
  3147.                     elif params[1] == "info":
  3148.                         formatting = ": "+cfix()+"reward shop info [category] [item]"
  3149.                         if len(params) == 2:
  3150.                             formatting = ": "+cfix()+"reward shop info"
  3151.                             yield from client.send_message(message.channel, "<SHOP> " + get_cats(True))
  3152.                         elif len(params) == 3:
  3153.                             formatting = ": "+cfix()+"reward shop info [category]"
  3154.                             line = get_items(params[2], True)
  3155.                             if line is not None:
  3156.                                 yield from client.send_message(message.channel, "<SHOP> " + line)
  3157.                             else:
  3158.                                 yield from client.send_message(message.channel, "<SHOP> Couldn't find a category named " + params[2])
  3159.                         else:
  3160.                             formatting = ": "+cfix()+"reward shop info [category] [item]"
  3161.                             catname = params[2]
  3162.                             if catname in money_shop:
  3163.                                 yield from client.send_message(message.channel, get_item_desc(money_shop[catname], params[3], True))
  3164.                             else:
  3165.                                 yield from client.send_message(message.channel, "<SHOP> Couldn't find a category named " + catname)
  3166.                         sucess = True
  3167.                     else:
  3168.                         raise(Exception())
  3169.                 else:
  3170.                     raise(Exception())
  3171.             except:
  3172.                 yield from client.send_message(message.channel, "<RWD> Failed" + formatting)
  3173.         elif is_command(message.content, "plugin"):
  3174.             formatting = ": "+cfix()+"plugin help"
  3175.             try:
  3176.                 params = [""]
  3177.                 if " " in message.content:
  3178.                     params = message.content[message.content.find(" ")+1:].split(" ")
  3179.                 if params[0] == "install":
  3180.                     formatting + ": "+cfix()+"plugin install <plugin> <link> - are you sure that link is correct?"
  3181.                     if not check_command(message.author.name, "plugin install", "plugin"):
  3182.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3183.                     else:
  3184.                         link = " ".join(params[2:])
  3185.                         if "pastebin" in link:
  3186.                             if "/raw/" in link:
  3187.                                 if os.path.exists("plugins/"+params[1]+".py"):
  3188.                                     os.remove("plugins/"+params[1]+".py")
  3189.                                 plugin_manager.uninstall(params[1])
  3190.                                 download_plugin(" ".join(params[2:]), params[1])
  3191.                                 test = __import__("plugins."+params[1], fromlist=["plugins"])
  3192.                                 test.setup(plugin_manager, params[1])
  3193.                                 yield from client.send_message(message.channel, "<PLUG> Installed plugin " + params[1])
  3194.                                 sucess = True
  3195.                             else:
  3196.                                 yield from client.send_message(message.channel, "<PLUG> Must be a raw link!")
  3197.                         else:
  3198.                             yield from client.send_message(message.channel, "<PLUG> Must be a pastebin link!")
  3199.                 elif params[0] == "uninstall":
  3200.                     formatting + ": "+cfix()+"plugin uninstall <plugin>"
  3201.                     if not check_command(message.author.name, "plugin uninstall", "plugin"):
  3202.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3203.                     else:
  3204.                         if "__init__" not in params[1]:
  3205.                             if os.path.exists("plugins/"+params[1]+".py"):
  3206.                                 os.remove("plugins/"+params[1]+".py")
  3207.                             plugin_manager.uninstall(params[1])
  3208.                             yield from client.send_message(message.channel, "<PLUG> uninstalled " + params[1] + " (if it was installed)")
  3209.                         else:
  3210.                             yield from client.send_message(message.channel, "<PLUG> You can't uninstall the __init__...")
  3211.                 elif params[0] == "disable":
  3212.                     formatting + ": "+cfix()+"plugin disable <plugin>"
  3213.                     if not check_command(message.author.name, "plugin disable", "plugin"):
  3214.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3215.                     else:
  3216.                         if "__init__" not in params[1]:
  3217.                             if not plugin_disabled(params[1]):
  3218.                                 plugin_manager.uninstall(params[1])
  3219.                                 plugin_disables[params[1]] = True
  3220.                                 save_plugin_disables()
  3221.                                 yield from client.send_message(message.channel, "<PLUG> Disabled " + params[1])
  3222.                             else:
  3223.                                 yield from client.send_message(message.channel, "<PLUG> " + params[1] + " already disabled!")
  3224.                         else:
  3225.                             yield from client.send_message(message.channel, "<PLUG> You can't disable the __init__...")
  3226.                 elif params[0] == "enable":
  3227.                     formatting + ": "+cfix()+"plugin disable <plugin>"
  3228.                     if not check_command(message.author.name, "plugin disable", "plugin"):
  3229.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3230.                     else:
  3231.                         if "__init__" not in params[1]:
  3232.                             if plugin_disabled(params[1]):
  3233.                                 plugin_disables[params[1]] = False
  3234.                                 save_plugin_disables()
  3235.                                 test = __import__("plugins."+params[1], fromlist=["plugins"])
  3236.                                 test.setup(plugin_manager, params[1])
  3237.                                 yield from client.send_message(message.channel, "<PLUG> Enabled " + params[1])
  3238.                             else:
  3239.                                 yield from client.send_message(message.channel, "<PLUG> " + params[1] + " already enabled!")
  3240.                         else:
  3241.                             yield from client.send_message(message.channel, "<PLUG> You can't enable the __init__...")
  3242.                 elif params[0] == "check":
  3243.                     formatting + ": "+cfix()+"plugin check <plugin>"
  3244.                     if not check_command(message.author.name, "plugin check", "plugin"):
  3245.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3246.                     else:
  3247.                         if "__init__" not in params[1]:
  3248.                             line = "enabled"
  3249.                             if plugin_disabled(params[1]):
  3250.                                 line = "disabled"
  3251.                             yield from client.send_message(message.channel, "<ROLE> " + params[1] + " is currently " + line)
  3252.                         else:
  3253.                             yield from client.send_message(message.channel, "<PLUG> You can't enable the __init__...")
  3254.                 elif params[0] == "update":
  3255.                     formatting + ": "+cfix()+"plugin update <plugin>"
  3256.                     if not check_command(message.author.name, "plugin update", "plugin"):
  3257.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3258.                     else:
  3259.                         if "__init__" not in params[1]:
  3260.                             if update_plugin(params[1]):
  3261.                                 plugin_manager.uninstall(params[1])
  3262.                                 if not plugin_disabled(params[1]):
  3263.                                     test = __import__("plugins."+params[1], fromlist=["plugins"])
  3264.                                     test.setup(plugin_manager, params[1])
  3265.                                 yield from client.send_message(message.channel, "<PLUG> Updated " + params[1])
  3266.                             else:
  3267.                                 yield from client.send_message(message.channel, "<PLUG> Couldn't find a plugin named "+params[1]+"!")
  3268.                         else:
  3269.                             yield from client.send_message(message.channel, "<PLUG> You can't update the __init__...")
  3270.                 elif params[0] == "list":
  3271.                     formatting + ": "+cfix()+"plugin list?"
  3272.                     if not check_command(message.author.name, "plugin list", "plugin"):
  3273.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3274.                     else:
  3275.                         yield from client.send_message(message.channel, "<PLUG> Loaded plugins: " + ", ".join(plugin_manager.plugin_name_list()))
  3276.                     sucess = True
  3277.                 elif params[0] == "reload":
  3278.                     formatting + ": "+cfix()+"plugin reload"
  3279.                     if not check_command(message.author.name, "plugin reload", "plugin"):
  3280.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3281.                     else:
  3282.                         plugin_list = plugin_manager.plugin_name_list()
  3283.                         for plugin in plugin_list:
  3284.                             plugin_manager.uninstall(plugin)
  3285.                             test = __import__("plugins."+plugin, fromlist=["plugins"])
  3286.                             test.setup(plugin_manager, plugin)
  3287.                         yield from client.send_message(message.channel, "<PLUG> Reloaded plugins.")
  3288.                     sucess = True
  3289.                 elif params[0] == "help":
  3290.                     formatting = ": "+cfix()+"plugin help [page]"
  3291.                     if not check_command(message.author.name, "plugin help", "plugin"):
  3292.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3293.                     else:
  3294.                         page = 0
  3295.                         if len(params) > 1:
  3296.                             page = int(params[1]) - 1
  3297.                         lines = print_help(plugin_help_str, page)
  3298.                         if lines is not None:
  3299.                             for line in lines: yield from client.send_message(message.author, line)
  3300.                             sucess = True
  3301.                         else:
  3302.                             yield from client.send_message(message.channel, "<PLUG> invalid page!")
  3303.                 else:
  3304.                     raise(Exception())
  3305.             except:
  3306.                 yield from client.send_message(message.channel, "<PLUG> Failed" + formatting)
  3307.         elif is_command(message.content, "bind"):
  3308.             formatting = ": "+cfix()+"+bind set|get|add|del <command> [bind]"
  3309.             try:
  3310.                 params = [""]
  3311.                 if " " in message.content:
  3312.                     params = message.content[message.content.find(" ")+1:].split(" ")
  3313.                 if params[0] == "set":
  3314.                     formatting = ": "+cfix()+"+bind set <command> <bind>"
  3315.                     if not check_command(message.author.name, "bind set", "bind"):
  3316.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3317.                     else:
  3318.                         set_bind(params[1], params[2])
  3319.                         yield from client.send_message(message.channel, "<BIND> Set " + params[1] +"'s binding to " + params[2])
  3320.                 elif params[0] == "get":
  3321.                     formatting = ": "+cfix()+"+bind get <command>"
  3322.                     if not check_command(message.author.name, "bind get", "bind"):
  3323.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3324.                     else:
  3325.                         b = get_binds(params[1])
  3326.                         if b is not None:
  3327.                             yield from client.send_message(message.channel, "<BIND> " + params[1] + "'s bindings: " + b)
  3328.                         else:
  3329.                             yield from client.send_message(message.channel, "<BIND> " + params[1] + " has not bindings!")
  3330.                 elif params[0] == "add":
  3331.                     formatting = ": "+cfix()+"+bind add <command> <bind>"
  3332.                     if not check_command(message.author.name, "bind add", "bind"):
  3333.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3334.                     else:
  3335.                         add_bind(params[1], params[2])
  3336.                         yield from client.send_message(message.channel, "<BIND> Added " + params[2] +" to " + params[1] + "'s binds")
  3337.                 elif params[0] == "del" or params[0] == "delete":
  3338.                     formatting = ": "+cfix()+"+bind del|delete <command> <bind>"
  3339.                     if not check_command(message.author.name, "bind add", "bind"):
  3340.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3341.                     else:
  3342.                         if remove_bind(params[1], params[2]):
  3343.                             yield from client.send_message(message.channel, "<BIND> Removed " + params[2] + " from " + params[1] + "'s bindings")
  3344.                         else:
  3345.                             yield from client.send_message(message.channel, "<BIND> Couldn't find a binding for " + params[1])
  3346.                 else:
  3347.                     raise(Exception())
  3348.             except:
  3349.                 yield from client.send_message(message.channel, "<BIND> Failed" + formatting)
  3350.         elif is_command(message.content, "settings"):
  3351.             formatting = ": "+cfix()+"settings set|get <setting> [value]"
  3352.             try:
  3353.                 params = [""]
  3354.                 if " " in message.content:
  3355.                     params = message.content[message.content.find(" ")+1:].split(" ")
  3356.                 if params[0] == "set":
  3357.                     formatting = ": "+cfix()+"settings set <setting> <value>"
  3358.                     if not check_command(message.author.name, "settings set", "settings"):
  3359.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3360.                     else:
  3361.                         settings[params[1]] = " ".join(params[2:])
  3362.                         save_settings()
  3363.                         if params[1] == "command_prefix":
  3364.                             load_help_strs()
  3365.                         elif params[1] == "radio_channel":
  3366.                             for ch in message.author.server.channels:
  3367.                                 if ch.name.lower() == rchn():
  3368.                                     radio_channel = ch
  3369.                                     break
  3370.                         yield from client.send_message(message.channel, "<STG> Set " + params[1] + " to " + settings[params[1]])
  3371.                     sucess = True
  3372.                 elif params[0] == "get":
  3373.                     formatting = ": "+cfix()+"settings get [setting]"
  3374.                     if not check_command(message.author.name, "settings get", "settings"):
  3375.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3376.                     else:
  3377.                         if len(params) == 1:
  3378.                             yield from client.send_message(message.channel, "<STG> current settings: " + ", ".join(settings.keys()))
  3379.                         else:
  3380.                             if params[1] in settings:
  3381.                                 yield from client.send_message(message.channel, "<STG> " + params[1] + " is set to " + settings[params[1]])
  3382.                             else:
  3383.                                 yield from client.send_message(message.channel, "<STG> Setting " + params[1] + " could not be found!")
  3384.                             sucess = True
  3385.                 else:
  3386.                     raise(Exception())
  3387.             except:
  3388.                 yield from client.send_message(message.channel, "<STG> Failed, usage: " + formatting)
  3389.         elif is_command(message.content, "shop"):
  3390.             formatting = ": see"+cfix()+"shop help"
  3391.             try:
  3392.                 params = [""]
  3393.                 if " " in message.content:
  3394.                     params = message.content[message.content.find(" ")+1:].split(" ")
  3395.                 if params[0] == "get":
  3396.                     formatting = ": "+cfix()+"shop get [category] [item]"
  3397.                     if not check_command(message.author.name, "shop get", "shop"):
  3398.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3399.                     else:
  3400.                         if len(params) == 1:
  3401.                             formatting = ": "+cfix()+"shop get"
  3402.                             yield from client.send_message(message.channel, "<SHOP> " + get_cats(False))
  3403.                         elif len(params) == 2:
  3404.                             formatting = ": "+cfix()+"shop get [category]"
  3405.                             line = get_shop_items(params[1], False)
  3406.                             if line is not None:
  3407.                                 yield from client.send_message(message.channel, "<SHOP> " + line)
  3408.                             else:
  3409.                                 yield from client.send_message(message.channel, "<SHOP> Couldn't find a category named " + params[2])
  3410.                         else:
  3411.                             formatting = ": "+cfix()+"shop get [category] [item]"
  3412.                             catname = params[1]
  3413.                             if catname in money_shop:
  3414.                                 yield from client.send_message(message.channel, get_item_desc(money_shop[catname], params[2], False))
  3415.                             else:
  3416.                                 yield from client.send_message(message.channel, "<SHOP> Couldn't find a category named " + catname)
  3417.                         sucess = True
  3418.                 elif params[0] == "buy":
  3419.                     formatting = ": "+cfix()+"shop but <category> <item>"
  3420.                     if not check_command(message.author.name, "shop buy", "shop"):
  3421.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3422.                     else:
  3423.                         catname = params[1]
  3424.                         if catname in money_shop:
  3425.                             itemname = params[2]
  3426.                             if itemname in money_shop[catname].items:
  3427.                                 item = money_shop[catname].items[itemname]
  3428.                                 reward = get_reward(item.reward)
  3429.                                 if reward is not None:
  3430.                                     money = get_money(message.author.name)
  3431.                                     if money > item.price:
  3432.                                         give_money(message.author.name, -item.price)
  3433.                                         yield from use_reward(message.author, message.channel, reward)
  3434.                                         yield from client.send_message(message.channel, "<SHOP> Item bought! Your balance is: " + str(get_money(message.author.name)))
  3435.                                     else:
  3436.                                         yield from client.send_message(message.channel, "<SHOP> You cannot afford that! Your balance is:" + str(money))
  3437.                                 else:
  3438.                                     yield from client.send_message(message.channel, "<SHOP> " + itemname + " has an invalid reward!")
  3439.                             else:
  3440.                                 yield from client.send_message(message.channel, "<SHOP> Couldn't find an item named " + itemname)
  3441.                         else:
  3442.                             yield from client.send_message(message.channel, "<SHOP> Couldn't find a category named " + catname)
  3443.                 elif params[0] == "help":
  3444.                     formatting = ": "+cfix()+"shop help"
  3445.                     if not check_command(message.author.name, "shop help", "role"):
  3446.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3447.                     else:
  3448.                         page = 0
  3449.                         if len(params) > 1:
  3450.                             page = int(params[1]) - 1
  3451.                         lines = print_help(shop_help_str, page)
  3452.                         if lines is not None:
  3453.                             for line in lines:
  3454.                                 yield from client.send_message(message.author, line)
  3455.                             sucess = True
  3456.                         else:
  3457.                             yield from client.send_message(message.channel, "<SHOP> invalid page!")
  3458.                 else:
  3459.                     raise(Exception())
  3460.             except:
  3461.                 yield from client.send_message(message.channel, "<SHOP> Failed, usage: " + formatting)
  3462.         elif is_command(message.content, "role"):
  3463.             formatting = ": see "+cfix()+"role help"
  3464.             try:
  3465.                 params = [""]
  3466.                 if " " in message.content:
  3467.                     params = message.content[message.content.find(" ")+1:].split(" ")
  3468.                 if params[0] == "set":
  3469.                     formatting = ": "+cfix()+"role set <username> <role>"
  3470.                     if not check_command(message.author.name, "role set", "role"):
  3471.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3472.                     else:
  3473.                         name = get_name(params[1].lower()).lower()
  3474.                         for mem in message.author.server.members:
  3475.                             if name in mem.name.lower():
  3476.                                 name = mem.name
  3477.                                 break
  3478.                         rolename = params[2]
  3479.                         if set_role(name, rolename):
  3480.                             yield from client.send_message(message.channel, "<ROLE> Set " + name + "'s role to " + rolename)
  3481.                         else:
  3482.                             yield from client.send_message(message.channel, "<ROLE> Couldn't set " + name + "'s name to " + rolename + " are you sure that role/user exist?")
  3483.                         sucess = True
  3484.                 elif params[0] == "help":
  3485.                     if not check_command(message.author.name, "role help", "role"):
  3486.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3487.                     else:
  3488.                         page = 0
  3489.                         if len(params) > 1:
  3490.                             page = int(params[1]) - 1
  3491.                         lines = print_help(role_help_str, page)
  3492.                         if lines is not None:
  3493.                             for line in lines:
  3494.                                 yield from client.send_message(message.author, line)
  3495.                             sucess = True
  3496.                         else:
  3497.                             yield from client.send_message(message.channel, "<ROLE> invalid page!")
  3498.                 elif params[0] == "edit":
  3499.                     formatting = ": "+cfix()+"role edit <rolename> <changes>"
  3500.                     if not check_command(message.author.name, "role edit", "role"):
  3501.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3502.                     else:
  3503.                         rolename = params[1]
  3504.                         changes = params[2:]
  3505.                         if change_permissions(rolename, changes):
  3506.                             save_permissions()
  3507.                             yield from client.send_message(message.channel, "<ROLE> Edited " + rolename)
  3508.                         else:
  3509.                             yield from client.send_message(message.channel, "<ROLE> Couldn't edit " + rolename + "!")
  3510.                 elif params[0] == "new":
  3511.                     formatting = ": "+cfix()+"role new <rolename>"
  3512.                     if not check_command(message.author.name, "role new", "role"):
  3513.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3514.                     else:
  3515.                         rolename = params[1]
  3516.                         if create_permissions(rolename):
  3517.                             yield from client.send_message(message.channel, "<ROLE> Created role " + rolename)
  3518.                         else:
  3519.                             yield from client.send_message(message.channel, "<ROLE> " + rolename + " already exists!")
  3520.                 elif params[0] == "get":
  3521.                     formatting = ": "+cfix()+"role get <rolename>"
  3522.                     if not check_command(message.author.name, "role get", "role"):
  3523.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3524.                     else:
  3525.                         rolename = params[1]
  3526.                         if rolename in permissions:
  3527.                             yield from client.send_message(message.channel, "<ROLE> " + rolename + " permissions: " + permissions[rolename].get_str())
  3528.                         else:
  3529.                             yield from client.send_message(message.channel, "<ROLE> " + rolename + " doesn't exist!")
  3530.                 elif params[0] == "roles":
  3531.                     formatting = ": "+cfix()+"role roles"
  3532.                     if not check_command(message.author.name, "role roles", "role"):
  3533.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3534.                     else:
  3535.                         yield from client.send_message(message.channel, "<ROLE> current roles: " + ", ".join(permissions.keys()))
  3536.                 elif params[0] == "check":
  3537.                     formatting = ": "+cfix()+"role check <username>"
  3538.                     if not check_command(message.author.name, "role check", "role"):
  3539.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3540.                     else:
  3541.                         name = get_name(params[1].lower()).lower()
  3542.                         for mem in message.author.server.members:
  3543.                             if name in mem.name.lower():
  3544.                                 name = mem.name
  3545.                                 break
  3546.                         role = get_role(name)
  3547.                         if role is not None:
  3548.                             yield from client.send_message(message.channel, "<ROLE> " + name + "'s role is " + role.name)
  3549.                         else:
  3550.                             yield from client.send_message(message.channel, "<ROLE> Couldn't find role, are you sure that user exists?")
  3551.                 elif params[0] == "":
  3552.                     formatting = ": "+cfix()+"role"
  3553.                     if not check_command(message.author.name, "role check", "role"):
  3554.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3555.                     else:
  3556.                         role = get_role(message.author.name)
  3557.                         if role is None:
  3558.                             yield from client.send_message(message.channel, "<ROLE> You have an invalid role! setting yours to default.")
  3559.                             set_role(message.author.name, "DEFAULT")
  3560.                         else:
  3561.                             yield from client.send_message(message.channel, "<ROLE> your role is " + role.name)
  3562.                 else:
  3563.                     raise(Exception())
  3564.             except:
  3565.                 yield from client.send_message(message.channel, "<ROLE> Failed, usage: " + formatting)
  3566.         elif is_command(message.content, "purge"):
  3567.             global current_reward_checker
  3568.             try:
  3569.                 if not check_command(message.author.name, "purge"):
  3570.                     yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3571.                 else:
  3572.                     params = [""]
  3573.                     if " " in message.content:
  3574.                         params = message.content[message.content.find(" ")+1:].split(" ")
  3575.                     current_reward_checker = Purger(" ".join(params[1:]))
  3576.                     limit = int(params[0])
  3577.                     yield from client.purge_from(message.channel, limit=limit, check=reward_checker)
  3578.                     yield from client.send_message(message.channel, "<PURGE> Purge complete.")
  3579.             except:
  3580.                 yield from client.send_message(message.channel, "<PURGE> usage: !purge <limit> <checker>")
  3581.         elif is_command(message.content, "custom"):
  3582.             formatting = ": "+cfix()+"custom set|get|del <command> [reward]"
  3583.             try:
  3584.                 params = [""]
  3585.                 if " " in message.content:
  3586.                     params = message.content[message.content.find(" ")+1:].split(" ")
  3587.                 if params[0] == "set":
  3588.                     formatting = ": "+cfix()+"custom set <command> <reward>"
  3589.                     if not check_command(message.author.name, "custom set", "custom"):
  3590.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3591.                     else:
  3592.                         custom_commands[params[1]] = params[2]
  3593.                         add_bind("__custom", params[1])
  3594.                         save_custom_commands()
  3595.                         yield from client.send_message(message.channel, "<CSTM> Set " + params[1] + " to " + params[2])
  3596.                 elif params[0] == "get":
  3597.                     formatting = ": "+cfix()+"custom get <command>"
  3598.                     if not check_command(message.author.name, "custom set", "custom"):
  3599.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3600.                     else:
  3601.                         if params[1] in custom_commands:
  3602.                             yield from client.send_message(message.channel, "<CSTM> " + params[1] + " is set to " + custom_commands[params[1]])
  3603.                         else:
  3604.                             yield from client.send_message(message.channel, "<CSTM> " + params[1] + " is not a custom command")
  3605.                 elif params[0] == "del":
  3606.                     formatting = ": "+cfix()+"custom del <command>"
  3607.                     if not check_command(message.author.name, "custom del", "custom"):
  3608.                         yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3609.                     else:
  3610.                         if params[1] in custom_commands:
  3611.                             del custom_commands[params[1]]
  3612.                             remove_bind("__custom", params[1])
  3613.                             save_custom_commands()
  3614.                             yield from client.send_message(message.channel, "<CSTM> Deleted custom command " + params[1])
  3615.                         else:
  3616.                              yield from client.send_message(message.channel, "<CSTM> " + params[1] + " is not a custom command")
  3617.                 else:
  3618.                     raise(Exception())
  3619.             except:
  3620.                 yield from client.send_message(message.channel, "<ROLE> Failed, usage: " + formatting)
  3621.         elif is_command(message.content, "__custom"):
  3622.             cmd = message.content[len(cfix()):]
  3623.             if " " in cmd:
  3624.                 cmd = cmd[:cmd.find(" ")]
  3625.             if cmd in custom_commands:
  3626.                 if not check_command(message.author.name, "_custom " + cmd, "_custom"):
  3627.                     yield from client.send_message(message.channel, "<ROLE> You don't have permission to use that command!")
  3628.                 else:
  3629.                     reward = get_reward(custom_commands[cmd])
  3630.                     if reward is not None:
  3631.                         yield from use_reward(message.author, message.channel, reward)
  3632.                     else:
  3633.                         yield from client.send_message(message.channel, "<CSTM> Custom command reward " + custom_commands[cmd] + " doesn't exist.")
  3634.             else:
  3635.                 yield from client.send_message(message.channel, "<CSTM> Custom command " + cmd + " has no command?")
  3636.         else:
  3637.             yield from plugin_manager.on_message(message)
  3638.     if sucess and not message.channel.is_private:
  3639.         yield from client.delete_message(message)
  3640.  
  3641.  
  3642. @asyncio.coroutine
  3643. def check_song(loop):
  3644.     while True:
  3645.         global voice_chn, song_finished, song_paused
  3646.         if voice_chn is not None and song_finished and not song_paused:
  3647.             yield from next_song()
  3648.         yield from asyncio.sleep(ruprt())
  3649.  
  3650.  
  3651. @client.event
  3652. @asyncio.coroutine
  3653. def on_ready():
  3654.     print('Logged in as')
  3655.     print(client.user.name)
  3656.     print(client.user.id)
  3657.     time.clock()
  3658.     setup_variables()
  3659.     load_songs()
  3660.     load_tag()
  3661.     load_nicks()
  3662.     load_messages()
  3663.     load_tag_stats()
  3664.     load_hangman_words()
  3665.     load_activity()
  3666.     load_activity_events()
  3667.     load_activity_triggers()
  3668.     load_permissions()
  3669.     load_roles()
  3670.     load_money()
  3671.     load_rewards()
  3672.     load_shop()
  3673.     load_binds()
  3674.     load_settings()
  3675.     load_custom_commands()
  3676.     load_plugin_disables()
  3677.     print("Loaded files")
  3678.     print('------')
  3679.     print("Loading plugins:")
  3680.     load_plugins()
  3681.     print("Loading help files:")
  3682.     load_help_strs()
  3683.     print("done!")
  3684.  
  3685.     global uptime_start
  3686.     uptime_start = create_current_dat()
  3687.  
  3688.     loop = asyncio.get_event_loop()
  3689.     yield from check_song(loop)
  3690.  
  3691. def run():
  3692.     print("Type setup to enter setup, otherwise press enter to start bot")
  3693.     if input().lower() == "setup":
  3694.         setup.run()
  3695.         run()
  3696.     else:
  3697.         print("Starting the bot...")
  3698.         if os.path.exists("credentials.txt"):
  3699.             username = None
  3700.             password = None
  3701.             token = None
  3702.             f = open("credentials.txt", "r")
  3703.             for line in f:
  3704.                 spl = line.replace("\n", "").split("=")
  3705.                 if spl[0].lower() == "user" or spl[0].lower() == "username":
  3706.                     username = "=".join(spl[1:])
  3707.                 elif spl[0].lower() == "pass" or spl[0].lower() == "password":
  3708.                     password = "=".join(spl[1:])
  3709.                 elif spl[0].lower() == "token":
  3710.                     token = "=".join(spl[1:])
  3711.             if username is not None and password is not None:
  3712.                 print("loaded username and password...")
  3713.                 client.run(username, password)
  3714.             elif token is not None:
  3715.                 print("loaded bot token...")
  3716.                 client.run(token)
  3717.             else:
  3718.                 print("Couldn't find credentials!")
  3719.         else:
  3720.             print("Credential file missing, have you run the setup?")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement