Alyssa

discord_bot

Jun 10th, 2016
1,343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 24.62 KB | None | 0 0
  1. import copy
  2. import discord
  3. import discord_gateway
  4. import json
  5. import os
  6. import random
  7. from threading import Thread
  8. import time
  9.  
  10. #Discord API (discord): http://pastebin.com/TDfpr7qc
  11. #Discord Gateway (discord_gateway): http://pastebin.com/peEJZanf
  12.  
  13. config_path = "/root/Discord/bond"
  14. auth_path = "/root/Discord/bots/auths.json"
  15.  
  16. device = "Tron#0056's Multi-Bot System"
  17.  
  18. praises = [
  19.     "USER looks beautiful.",
  20.     "Everyone loves USER.",
  21.     "I <3 USER.",
  22.     "MASTER is in love with USER.",
  23.     "USER is a great person.",
  24.     "I nominate USER for president.",
  25.     "USER is probably a communist. :D",
  26.     "USER is better than MASTER.",
  27.     "USER, You are the greatest person ever.",
  28.     "USER can do nothing wrong.",
  29.     "USER does everything right!",
  30.     "USER did nothing wrong.",
  31.     "USER is better than ME",
  32.     "USER is the best person in this chat.",
  33.     "We all love USER!"
  34.     ]
  35.  
  36. insults = [
  37.     "USER looks like a pinecone!",
  38.     "USER looks like a snowman!",
  39.     "USER probably isn't even a communist.",
  40.     "No one likes USER.",
  41.     "No one would miss USER.",
  42.     "USER is the reason cancer exists",
  43.     "Cancer would be a preferable alternative to USER.",
  44.     "I'd rather drink bleach than even see USER.",
  45.     "Does anyone else think USER should die?",
  46.     "USER is probably salty he isn't as swag as me.",
  47.     "USER isn't /that/ bad of a guy, I guess.",
  48.     "USER probably uses a script.",
  49.     "If USER left this chat we'd hold a party.",
  50.     "USER is so boring /I/ almost fell asleep.",
  51.     "I don't believe what they say about you USER <3",
  52.     "What they say about USER is probably true."
  53.     ]
  54.  
  55. deaths = [
  56.     "USER fell off a cliff.",
  57.     "USER hit the ground too hard",
  58.     "USER got shot.",
  59.     "USER spontaneously combusted.",
  60.     "I shot USER.",
  61.     "USER got derezzed.",
  62.     "USER died of old age.",
  63.     "USER burned to death.",
  64.     "USER drowned.",
  65.     "MASTER shot USER.",
  66.     "USER rebelled against MASTER for the last time.",
  67.     "MASTER and USER both died together.",
  68.     "USER died of cancer.",
  69.     "MASTER infected USER with a virus, he died.",
  70.     "USER died.",
  71.     "USER fell into a macerator.",
  72.     "USER was mobbed.",
  73.     "USER was impaled by a pitchfork.",
  74.     "USER drank too much bleach.",
  75.     "USER is a spooOOOoooky ghost now!",
  76.     "USER got sent to the moon.",
  77.     "USER found their inner skeleton.",
  78.     "MASTER back-stabbed USER.",
  79.     "USER tried and failed to assassinate MASTER.",
  80.     "USER went back in time and got killed by a dinosaur.",
  81.     "USER was abducted by aliens.",
  82.     "USER got hanged.",
  83.     "USER was sentenced to death for his crimes.",
  84.     "USER vanished, never to be seen again.",
  85.     "MASTER was thrown into a furnace by USER :(",
  86.     "USER insulted RedRobin, this was not a good idea.",
  87.     "RedRobin pecked USER to death."
  88.     ]
  89.  
  90. def omega_handler(self, message):
  91.     prefix = "!"
  92.     msg = json.loads(message)
  93.     if msg["op"] == 0:
  94.         if msg["t"] == "MESSAGE_CREATE":
  95.             event_data = msg["d"]
  96.             content = event_data["content"]
  97.             user = discord.User(event_data["author"])
  98.             username = user.username
  99.             user_discriminator = user.discriminator
  100.             channel = event_data["channel_id"]
  101.             if not channel in self.channels:
  102.                 self.channels[channel] = self.discord.get_channel(channel)
  103.             current_channel = self.channels[channel]
  104.             channel_type = current_channel.channel_type
  105.             print(username + "#" + str(user_discriminator) + ": " + content)
  106.             args = content.split(" ")
  107.             try:
  108.                 if args[0].lower() == prefix + "ping":
  109.                     #print("Responding to ping...")
  110.                     if len(args) == 1:
  111.                         current_channel.send("Pong!")
  112.                     else:
  113.                         rest = content[5 + len(prefix):len(content)]
  114.                         current_channel.send(rest)
  115.             except KeyError:
  116.                 print("Probably hit a rate limit...")
  117.  
  118. def bond_handler(self, message):
  119.     #Bond, James Bond.
  120.     version = "2.5"
  121.     change_prefix_level = 5
  122.     generate_number_level = 15
  123.     generate_giant_level = 60
  124.     change_any_prefix_level = 25
  125.     change_status_level = 60
  126.     create_forcefield_level = 25
  127.     suffix = "illion"
  128.     first_numbers = ['', 'thousand', 'million', 'billion', 'trillion', 'quadrillion', 'quintillion', 'sextillion', 'septillion', 'octillion', 'nonillion']
  129.     mono_numbers = ['','un', 'duo', 'tre', 'quattour', 'quin', 'sex', 'septen', 'octo', 'novem']
  130.     dec_numbers = ['','dec', 'vigint', 'trigint', 'quadragint', 'quinquagint', 'sexagint', 'septuagint', 'octogint', 'nonagint']
  131.     cent_numbers = ['', 'cent', 'ducent', 'trecent', 'quadringent', 'quingent', 'sescent', 'septingent', 'octingent', 'nongent']
  132.     milli_numbers = ['', 'millin', 'dumill', "tremill", 'quattourmill', 'quinmill', 'sexmill', 'septenmill', 'octomill', 'novemill']
  133.     milli_numbers_alt = ['','milli', 'dumilli', 'tremilli', 'quattourmilli', 'quinmilli', 'sexmilli', 'septenmilli', 'octomilli', "novemilli"]
  134.     max_mod_number = 52
  135.     max_admin_number = 1002
  136.     tts_sent = 1
  137.     try:
  138.         if self.forcefields:
  139.             pass
  140.     except AttributeError:
  141.         self.forcefields = []
  142.     try:
  143.         if self.ff_active:
  144.             pass
  145.     except AttributeError:
  146.         self.ff_active = True
  147.         self.user_data = {}
  148.         print("Started forcefield generator.")
  149.         self.ff_generator = Thread(target = ff_generator, args = [self] )
  150.         self.ff_generator.start()
  151.     if message != "":
  152.             try:
  153.                 msg = json.loads(message) #ValueError
  154.             except ValueError:
  155.                 msg = {"op": "-1"}
  156.                 print("NON-JSON MESSAGE: " + message)
  157.             self.previous = msg
  158.             if msg["op"] == 0:
  159.                 if msg["t"] == "MESSAGE_CREATE":
  160.                     event_data = msg["d"]
  161.                     content = event_data["content"]
  162.                     args = content.split(" ")
  163.                     user = discord.User(event_data["author"])
  164.                     channel = event_data["channel_id"]
  165.                    
  166.                     if not channel in self.channels:
  167.                         self.channels[channel] = self.discord.get_channel(channel)
  168.                    
  169.                     current_channel = self.channels[channel]
  170.                     channel_type = current_channel.channel_type
  171.                    
  172.                     if channel_type == "guild":
  173.                         if not current_channel.guild_id in self.guilds:
  174.                             self.guilds[current_channel.guild_id] = self.discord.get_guild(current_channel.guild_id)
  175.                         current_guild = self.guilds[current_channel.guild_id]
  176.                    
  177.                     if not os.path.exists(config_path):
  178.                         os.makedirs(config_path)
  179.                    
  180.                     if not os.path.isfile(config_path + "/prefix.json"):
  181.                         with open(config_path + "/prefix.json", "x") as f:
  182.                             default_prefixes = {"default": "."}
  183.                             f.write(json.dumps(default_prefixes))
  184.                    
  185.                     if not os.path.isfile(config_path + "/permissions.json"):
  186.                         with open(config_path + "/permissions.json", "x") as f:
  187.                             default_permissions = {
  188.                                 "default": 0,
  189.                                 "115659366337740809": 100}
  190.                             f.write(json.dumps(default_permissions))
  191.                    
  192.                     with open(config_path + "/prefix.json", "r") as f:
  193.                         prefixes = json.loads(f.read())
  194.                    
  195.                     with open(config_path + "/permissions.json", "r") as f:
  196.                         permissions = json.loads(f.read())
  197.                    
  198.                     if channel_type == "guild":
  199.                         if current_guild.id in prefixes:
  200.                             prefix = prefixes[current_guild.id]
  201.                         else:
  202.                             prefix = prefixes["default"]
  203.                     else:
  204.                         if channel_type in prefixes:
  205.                             prefix = prefixes[channel_type]
  206.                         else:
  207.                             prefix = prefixes["default"]
  208.                    
  209.                     try:
  210.                         if content[0:len(prefix)].lower() == prefix and user.bot == False:
  211.                             command = args[0].lower()
  212.                             command = command[len(prefix):len(command)]
  213.                             if command == "help":
  214.                                 current_channel.send( "```Info: \n "
  215.                                     + "This is a simple test chatbot\n"
  216.                                     + "\n"
  217.                                     + "Commands: \n"
  218.                                     + prefix + "info          | Displays bot info.\n"
  219.                                     + prefix + "help          | Displays help message.\n"
  220.                                     + prefix + "tts <message> | Sends a tts message.\n"
  221.                                     + prefix + "praise <user> | Praises user.\n"
  222.                                     + prefix + "insult <user> | Insults user.\n"
  223.                                     + prefix + "kill <user>   | Kills user.\n"
  224.                                     + prefix + "eval <math>   | Does mathemagics.\n"
  225.                                     + "\n"
  226.                                     + prefix + "adminhelp     | Admin only help message."
  227.                                     + "```" )
  228.                             elif command == "info":
  229.                                 current_channel.send("```James_Bond#0007 Created By Tron#0056\n"
  230.                                     + "Coded in python with custom discord ( v" + discord.version + " ) and gateway ( v" + discord_gateway.version + " ) frameworks.\n"
  231.                                     + "Bot version " + version + "\n"
  232.                                     + "Help command: " + prefix + "help```")
  233.                             elif command ==  "adminhelp":
  234.                                 if user.id in permissions:
  235.                                     if permissions[user.id] >= 1:
  236.                                         current_channel.send( "```Admin Help: \n"
  237.                                         + prefix + "adminhelp                     | Displays Admin Help\n"
  238.                                         + prefix + "setprefix <prefix> [location] | Sets prefix for location, defaults to\n"
  239.                                         + prefix + "setprefix <prefix> [location] | current.\n"
  240.                                         + prefix + "setlevel <user> <level>       | Sets level of user to level\n"
  241.                                         + prefix + "getlevel [user]               | Gets level of user, defaults to self\n"
  242.                                         + prefix + "setstatus <status>            | Sets the bot's status.\n"
  243.                                         + prefix + "giantnumber <how_big> [tts]   | Creates a giant number, can display\n"
  244.                                         + prefix + "giantnumber <how_big> [tts]   | with tts.\n"
  245.                                         + prefix + "ff <channel> <bounce to>      | Created a forcefield at <channel> that\n"
  246.                                         + prefix + "ff <channel> <bounce to>      | bounces to <bounce to>\n"
  247.                                         + prefix + "listff                        | Lists forcefields\n"
  248.                                         + prefix + "deleteff <id>                 | Deletes forcefield of id <id>\n"
  249.                                         + prefix + "deleteff <id>                 | (Warning: Changes other ff's ids.)\n"
  250.                                         + "```")
  251.                                     else:
  252.                                         current_channel.send( "<@!" + user.id + "> Permission level 1 or above is required for this command." )
  253.                                 else:
  254.                                     current_channel.send( "<@!" + user.id + "> Permission level 1 or above is required for this command." )
  255.                             elif command == "eval":
  256.                                 expression = content[len(args[0])+1:]
  257.                                 try:
  258.                                     result = eval(expression)
  259.                                 except SyntaxError:
  260.                                     result = "nil"
  261.                                 current_channel.send(expression + " = " + str(result))
  262.                             elif command == "setprefix":
  263.                                 if user.id in permissions:
  264.                                     if permissions[user.id] >= change_prefix_level:
  265.                                         if len(args) == 2:
  266.                                             if channel_type == "guild":
  267.                                                 prefixes[current_guild.id] = args[1].lower()
  268.                                                 current_channel.send("```Set prefix for " + current_guild.name + " to " + args[1].lower() + "```")
  269.                                             else:
  270.                                                 prefixes[channel_type] = args[1].lower()
  271.                                                 current_channel.send("```Set prefix for " + channel_type + "s to " + args[1].lower() + "```")
  272.                                         elif len(args) >= 3 and permissions[user.id] >= change_any_prefix_level:
  273.                                             prefixes[args[2]] = args[1].lower()
  274.                                             current_channel.send("```Set prefix for " + args[2] + " to " + args[1].lower() + "```")
  275.                                         else:
  276.                                             current_channels.send("<@!" + user.id + "> Permission level " + str( change_any_prefix_level ) + " required, your level is: " + str( permissions[user.id] ) )
  277.                                         with open(config_path + "/prefix.json", "w") as f:
  278.                                             f.write(json.dumps(prefixes))
  279.                                     else:
  280.                                         current_channels.send("<@!" + user.id + "> Permission level " + str( change_prefix_level ) + " required, your level is: " + str( permissions[user.id] ) )
  281.                                 else:
  282.                                     current_channels.send("<@!" + user.id + "> Permission level " + str( change_prefix_level ) + " is required for this command." )
  283.                             elif command == "setstatus":
  284.                                 if user.id in permissions:
  285.                                     if permissions[user.id] >= change_status_level:
  286.                                         self.send(3, {"idle_since": None, "game": { "name": content[ len( args[0] )+1: ] } } )
  287.                                         current_channel.send("Set status to " + content[len(args[0])+1:] )
  288.                                     else:
  289.                                         current_channels.send("<@!" + user.id + "> Permission level " + str( change_status_level ) + " required, your level is: " + str( permissions[user.id] ) )
  290.                                 else:
  291.                                     current_channels.send("<@!" + user.id + "> Permission level " + str( change_status_level ) + " required, your level is: " + str( 0 ) )
  292.                             elif command == "setlevel":
  293.                                 target = args[1]
  294.                                 try:
  295.                                     desired_level = int(args[2])
  296.                                 except ValueError:
  297.                                     desired_level = 0
  298.                                
  299.                                 if target[0:3] == "<@!":
  300.                                     target = target[3:len(target)-1]
  301.                                 elif target[0:2] == "<@":
  302.                                     target = target[2:len(target)-1]
  303.                                
  304.                                 target_level = 0
  305.                                
  306.                                 if target in permissions:
  307.                                     target_level = permissions[target]
  308.                                
  309.                                 if user.id in permissions:
  310.                                     if permissions[user.id] > desired_level and permissions[user.id] > target_level:
  311.                                         permissions[target] = desired_level
  312.                                         with open(config_path + "/permissions.json", "w") as f:
  313.                                             f.write(json.dumps(permissions))
  314.                                         current_channel.send("Set <@!" + target + ">'s level to " + str( desired_level ) )
  315.                                     elif permissions[user.id] <= desired_level:
  316.                                         current_channel.send("Cannot set level higher than self.")
  317.                                     elif permissions[user.id] <= target_level:
  318.                                         current_channel.send("Can only set level of those lower in level.")
  319.                                 else:
  320.                                     current_channel.send("Insufficient permissions.")
  321.                             elif command == "ff":
  322.                                 if len(args) >= 3:
  323.                                     target = args[1]
  324.                                     if target[0:3] == "<#!":
  325.                                         target = target[3:len(target)-1]
  326.                                     elif target[0:2] == "<#":
  327.                                         target = target[2:len(target)-1]
  328.                                     bounceback = args[2]
  329.                                     if bounceback[0:3] == "<#!":
  330.                                         bounceback = bounceback[3:len(bounceback)-1]
  331.                                     elif bounceback[0:2] == "<#":
  332.                                         bounceback = bounceback[2:len(bounceback)-1]
  333.                                 else:
  334.                                     pass
  335.                                 if user.id in permissions:
  336.                                     if permissions[user.id] >= create_forcefield_level:
  337.                                         self.forcefields.append([target,bounceback, copy.deepcopy(self.user_data)])
  338.                                         current_channel.send("Created forcefield at <#" + target + "> that bounces to <#" + bounceback + ">")
  339.                                     else:
  340.                                         current_channel.send("Permission level " + str(create_forcefield_level) + " required, your level is " + str(permissions[user.id]))
  341.                                 else:
  342.                                     current_channel.send("Insufficient permissions.")
  343.                             elif command == "listff":
  344.                                 if user.id in permissions:
  345.                                     if permissions[user.id] >= create_forcefield_level:
  346.                                         to_return = ""
  347.                                         ff_id = 0
  348.                                         for ff in self.forcefields:
  349.                                             to_return += str(ff_id) + ": <#" + ff[0] + "> bounce to <#" + ff[1] + ">\n"
  350.                                             ff_id += 1
  351.                                         to_return += ""
  352.                                         current_channel.send(to_return)
  353.                                     else:
  354.                                         current_channel.send("Permission level " + str(create_forcefield_level) + " required, your level is " + str(permissions[user.id]))
  355.                                 else:
  356.                                     current_channel.send("Insufficient permissions.")
  357.                             elif command == "deleteff":
  358.                                 if user.id in permissions:
  359.                                     if permissions[user.id] >= create_forcefield_level:
  360.                                         if len(args) >= 2:
  361.                                             target_id = args[1]
  362.                                         try:
  363.                                             self.forcefields.pop(int(target_id))
  364.                                             current_channel.send("Deleted forcefield of ID " + str(target_id))
  365.                                         except IndexError:
  366.                                             current_channel.send("That ID does not exist!")
  367.                                         except TypeError:
  368.                                             current_channel.send("That is not a valid ID!")
  369.                                     else:
  370.                                         current_channel.send("Permission level " + str(create_forcefield_level) + " required, your level is " + str(permissions[user.id]))
  371.                                 else:
  372.                                     current_channel.send("Insufficient permissions.")
  373.                             elif command == "getlevel":
  374.                                 if len(args) >= 2:
  375.                                     target = args[1]
  376.                                     if target[0:3] == "<@!":
  377.                                         target = target[3:len(target)-1]
  378.                                     elif target[0:2] == "<@":
  379.                                         target = target[2:len(target)-1]
  380.                                 else:
  381.                                     target = user.id
  382.                                
  383.                                 if target in permissions:
  384.                                     current_channel.send("<@!" + target + ">'s permission level is " + str( permissions[ target ] ) )
  385.                                 else:
  386.                                     current_channel.send("<@!" + target + ">'s permission level is " + str( 0 ) )
  387.                             elif command == "giantnumber":
  388.                                 if user.id in permissions:
  389.                                     if permissions[user.id] >= generate_number_level:
  390.                                         if len(args) >= 2:
  391.                                             if len(args) == 3:
  392.                                                 if args[2] == "tts":
  393.                                                     go_on = True
  394.                                                 else:
  395.                                                     go_on = False
  396.                                             else:
  397.                                                 go_on = False
  398.                                            
  399.                                             try:
  400.                                                 how_big = int(args[1])
  401.                                                 if how_big > max_mod_number:
  402.                                                     if permissions[user.id] >= generate_giant_level:
  403.                                                         if how_big > max_admin_number:
  404.                                                             how_big = max_admin_number
  405.                                                     else:
  406.                                                         how_big = max_mod_number
  407.                                            
  408.                                             except ValueError:
  409.                                                 how_big = 1
  410.                                             result_number = ""
  411.                                             while how_big >= 1:
  412.                                                 how_big -= 1
  413.                                                 rand_number = random.randint(0,999)
  414.                                                 if rand_number > 0:
  415.                                                     if how_big < 11:
  416.                                                         result_number += " " + str(rand_number) + " " + first_numbers[how_big]
  417.                                                     elif how_big == 1001:
  418.                                                         result_number += " " + str(rand_number) + " " + milli_numbers[1] + suffix
  419.                                                     else:
  420.                                                         new_hb = how_big -1
  421.                                                         result_number += " " + str(rand_number) + " " + mono_numbers[new_hb % 10]  + dec_numbers[round(((new_hb % 100) - (new_hb % 10)) / 10)] + cent_numbers[round(((new_hb % 1000) - (new_hb % 100) - (new_hb % 10)) / 100)] + suffix
  422.                                            
  423.                                             to_say = result_number.lstrip().rstrip()
  424.                                             if go_on == True:
  425.                                                 while go_on == True:
  426.                                                     tts_sent += 1
  427.                                                     current_chunk = to_say[0:175]
  428.                                                     if current_chunk != "":
  429.                                                         if len(current_chunk) == 175:
  430.                                                             if current_chunk.rfind(" ") != -1:
  431.                                                                 current_chunk = current_chunk[0:current_chunk.rfind(" ")]
  432.                                                                 current_channel.send(current_chunk, nonce = tts_sent, tts = True)
  433.                                                                 time.sleep(2)
  434.                                                             else:
  435.                                                                 current_channel.send(current_chunk, nonce = tts_sent, tts = True)
  436.                                                         else:
  437.                                                             current_channel.send(current_chunk, nonce = tts_sent, tts = True)
  438.                                                     else:
  439.                                                         go_on = False
  440.                                                         print("[James_Bond] Ended number.")
  441.                                                     to_say = to_say[len(current_chunk):len(to_say)]
  442.                                             else:
  443.                                                 go_on = True
  444.                                                 while go_on == True:
  445.                                                     current_chunk = to_say[0:1999]
  446.                                                     if current_chunk != "":
  447.                                                         if len(current_chunk) == 1999:
  448.                                                             if current_chunk.rfind(" ") != -1:
  449.                                                                 current_chunk = current_chunk[0:current_chunk.rfind(" ")]
  450.                                                                 current_channel.send(current_chunk, tts = False)
  451.                                                                 time.sleep(2)
  452.                                                             else:
  453.                                                                 current_channel.send(current_chunk, tts = False)
  454.                                                         else:
  455.                                                             current_channel.send(current_chunk, tts = False)
  456.                                                     else:
  457.                                                         go_on = False
  458.                                                         print("[James Bond] Ended number.")
  459.                                                     to_say = to_say[len(current_chunk):len(to_say)]
  460.                                     else:
  461.                                         current_channels.send("<@!" + user.id + "> Permission level " + str( generate_number_level ) + " required, your level is: " + str( permissions[user.id] ) )
  462.                                 else:
  463.                                     current_channels.send("<@!" + user.id + "> Permission level " + str( generate_number_level ) + " required, your level is: " + str( 0 ) )
  464.                             elif command == "tts":
  465.                                 to_say = content[len(args[0])+1:]
  466.                                 go_on = True
  467.                                 while go_on == True:
  468.                                     tts_sent += 1
  469.                                     current_chunk = to_say[0:175]
  470.                                     if current_chunk != "":
  471.                                         if len(current_chunk) == 175:
  472.                                             if current_chunk.rfind(" ") != -1:
  473.                                                 current_chunk = current_chunk[0:current_chunk.rfind(" ")]
  474.                                                 current_channel.send(current_chunk, nonce = tts_sent, tts = True)
  475.                                                 time.sleep(2)
  476.                                             else:
  477.                                                 current_channel.send(current_chunk, nonce = tts_sent, tts = True)
  478.                                         else:
  479.                                             current_channel.send(current_chunk, nonce = tts_sent, tts = True)
  480.                                     else:
  481.                                         go_on = False
  482.                                         print("[James_Bond] Ended tts.")
  483.                                     to_say = to_say[len(current_chunk):len(to_say)]
  484.                             elif command == "praise":
  485.                                 if len(args) > 1:
  486.                                     target = args[1]
  487.                                 else:
  488.                                     if channel_type == "guild":
  489.                                         users = []
  490.                                         for gmember in current_guild.list_members(limit=100):
  491.                                             users.append(gmember.user)
  492.                                     else:
  493.                                         users = [current_channel.recipient]
  494.                                     target = "<@!" + random.choice(users).id + ">"
  495.                                 output = random.choice(praises)
  496.                                 output = output.replace("USER", target)
  497.                                 output = output.replace("MASTER", "<@" + user.id + ">")
  498.                                 output = output.replace("ME", "James_Bond")
  499.                                 current_channel.send(output)
  500.                             elif command == "insult":
  501.                                 if len(args) > 1:
  502.                                     target = args[1]
  503.                                 else:
  504.                                     if channel_type == "guild":
  505.                                         users = []
  506.                                         for gmember in current_guild.list_members(limit=100):
  507.                                             users.append(gmember.user)
  508.                                     else:
  509.                                         users = [current_channel.recipient]
  510.                                     target = "<@!" + random.choice(users).id + ">"
  511.                                 output = random.choice(insults)
  512.                                 output = output.replace("USER", target)
  513.                                 output = output.replace("MASTER", "<@" + user.id + ">")
  514.                                 output = output.replace("ME", "James_Bond")
  515.                                 current_channel.send(output)
  516.                             elif command == "kill":
  517.                                 if len(args) > 1:
  518.                                     target = args[1]
  519.                                 else:
  520.                                     if channel_type == "guild":
  521.                                         users = []
  522.                                         for gmember in current_guild.list_members(limit=100):
  523.                                             users.append(gmember.user)
  524.                                     else:
  525.                                         users = [current_channel.recipient]
  526.                                     target = "<@!" + random.choice(users).id + ">"
  527.                                 output = random.choice(deaths)
  528.                                 output = output.replace("USER", target)
  529.                                 output = output.replace("MASTER", "<@" + user.id + ">")
  530.                                 output = output.replace("ME", "James_Bond")
  531.                                 current_channel.send(output)
  532.                     except KeyError:
  533.                         print("Probably hit a rate limit")
  534.                 elif msg["t"] == "GUILD_CREATE":
  535.                     for voice_state in msg["d"]["voice_states"]:
  536.                         self.user_data[voice_state["user_id"]] = voice_state
  537.                         self.user_data[voice_state["user_id"]]["guild_id"] = msg["d"]["id"]
  538.                         #print("Added " + str(self.user_data))
  539.                 elif msg["t"] == "VOICE_STATE_UPDATE":
  540.                     event_data = msg["d"]
  541.                     try:
  542.                         if self.user_data[event_data["user_id"]]:
  543.                             pass
  544.                     except KeyError:
  545.                         self.user_data[event_data["user_id"]] = event_data
  546.                     self.user_data[event_data["user_id"]].update(event_data)
  547.     else:
  548.         print("Got blank message")
  549.         print("Last message was " + str(self.previous))
  550.         self.resume()
  551.  
  552. def ff_generator(self):
  553.     while True:
  554.         time.sleep(1)
  555.         #print("Whoosh")
  556.         #print(str(self.user_data))
  557.         for wud in self.user_data:
  558.             ud = self.user_data[wud]
  559.             hack_base = {"roles":[], "joined_at": 0, "deaf": False, "mute": False, "user":{
  560.                 "id": "0",
  561.                 "username": "nil",
  562.                 "discriminator": "0000",
  563.                 "avatar": "abcabc1234567890abcdef"
  564.             }}
  565.             #print(str(ud))
  566.             hack_base["user"]["id"] = ud["user_id"]
  567.             hack_user = discord.GuildMember(hack_base,self.discord.session, ud["guild_id"])
  568.             for ff in self.forcefields:
  569.                 if ud["user_id"] in ff[2]:
  570.                     prev_ud = ff[2][ud["user_id"]]
  571.                     if ud["channel_id"] !=  prev_ud["channel_id"]:
  572.                         if ud["channel_id"] == ff[0]: #If moved into ff'd channel
  573.                             hack_user.modify(channel_id = prev_ud["channel_id"])
  574.                         elif prev_ud["channel_id"] == ff[0]: #If moved away
  575.                             hack_user.modify(channel_id = ff[0])
  576.                         else:
  577.                             prev_ud["channel_id"] = ud["channel_id"]
  578.                 else: #If there is no previous user data
  579.                     hack_user.modify(channel_id = ff[1])
  580.  
  581. def handle(self, message):
  582.     msg = json.loads(message)
  583.  
  584. if not os.path.isfile(auth_path):
  585.     with open(auth_path, "x") as f:
  586.         f.write("[\n]")
  587.  
  588. with open(auth_path, "r") as f:
  589.     auths = json.loads( f.read() )
  590.  
  591. client_data = []
  592. num = 0
  593. for auth_info in auths:
  594.     auth = auth_info["auth"]
  595.     name = auth_info["name"]
  596.     if name == "James_Bond":
  597.         msg_handler = bond_handler
  598.     elif name == "Omega-Bot":
  599.         msg_handler = omega_handler
  600.     else:
  601.         msg_handler = handle
  602.     print("Doing " + name + "'s auth with " + auth)
  603.     try:
  604.         if num <= 1:
  605.             my_client = discord.Discord(auth, bot = True, user_agent = device)
  606.             is_bot = True
  607.         else:
  608.             my_client = discord.Discord(auth, bot = False, user_agent = device)
  609.             is_bot = False
  610.         client_data.append([
  611.             my_client,
  612.             discord_gateway.Client(auth, num, my_client, is_bot, message_handler = msg_handler, device = device),
  613.             num
  614.             ])
  615.     except UnboundLocalError:
  616.         print(auth + " failed.")
  617.     num += 1
  618.     time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment