Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import copy
- import discord
- import discord_gateway
- import json
- import os
- import random
- from threading import Thread
- import time
- #Discord API (discord): http://pastebin.com/TDfpr7qc
- #Discord Gateway (discord_gateway): http://pastebin.com/peEJZanf
- config_path = "/root/Discord/bond"
- auth_path = "/root/Discord/bots/auths.json"
- device = "Tron#0056's Multi-Bot System"
- praises = [
- "USER looks beautiful.",
- "Everyone loves USER.",
- "I <3 USER.",
- "MASTER is in love with USER.",
- "USER is a great person.",
- "I nominate USER for president.",
- "USER is probably a communist. :D",
- "USER is better than MASTER.",
- "USER, You are the greatest person ever.",
- "USER can do nothing wrong.",
- "USER does everything right!",
- "USER did nothing wrong.",
- "USER is better than ME",
- "USER is the best person in this chat.",
- "We all love USER!"
- ]
- insults = [
- "USER looks like a pinecone!",
- "USER looks like a snowman!",
- "USER probably isn't even a communist.",
- "No one likes USER.",
- "No one would miss USER.",
- "USER is the reason cancer exists",
- "Cancer would be a preferable alternative to USER.",
- "I'd rather drink bleach than even see USER.",
- "Does anyone else think USER should die?",
- "USER is probably salty he isn't as swag as me.",
- "USER isn't /that/ bad of a guy, I guess.",
- "USER probably uses a script.",
- "If USER left this chat we'd hold a party.",
- "USER is so boring /I/ almost fell asleep.",
- "I don't believe what they say about you USER <3",
- "What they say about USER is probably true."
- ]
- deaths = [
- "USER fell off a cliff.",
- "USER hit the ground too hard",
- "USER got shot.",
- "USER spontaneously combusted.",
- "I shot USER.",
- "USER got derezzed.",
- "USER died of old age.",
- "USER burned to death.",
- "USER drowned.",
- "MASTER shot USER.",
- "USER rebelled against MASTER for the last time.",
- "MASTER and USER both died together.",
- "USER died of cancer.",
- "MASTER infected USER with a virus, he died.",
- "USER died.",
- "USER fell into a macerator.",
- "USER was mobbed.",
- "USER was impaled by a pitchfork.",
- "USER drank too much bleach.",
- "USER is a spooOOOoooky ghost now!",
- "USER got sent to the moon.",
- "USER found their inner skeleton.",
- "MASTER back-stabbed USER.",
- "USER tried and failed to assassinate MASTER.",
- "USER went back in time and got killed by a dinosaur.",
- "USER was abducted by aliens.",
- "USER got hanged.",
- "USER was sentenced to death for his crimes.",
- "USER vanished, never to be seen again.",
- "MASTER was thrown into a furnace by USER :(",
- "USER insulted RedRobin, this was not a good idea.",
- "RedRobin pecked USER to death."
- ]
- def omega_handler(self, message):
- prefix = "!"
- msg = json.loads(message)
- if msg["op"] == 0:
- if msg["t"] == "MESSAGE_CREATE":
- event_data = msg["d"]
- content = event_data["content"]
- user = discord.User(event_data["author"])
- username = user.username
- user_discriminator = user.discriminator
- channel = event_data["channel_id"]
- if not channel in self.channels:
- self.channels[channel] = self.discord.get_channel(channel)
- current_channel = self.channels[channel]
- channel_type = current_channel.channel_type
- print(username + "#" + str(user_discriminator) + ": " + content)
- args = content.split(" ")
- try:
- if args[0].lower() == prefix + "ping":
- #print("Responding to ping...")
- if len(args) == 1:
- current_channel.send("Pong!")
- else:
- rest = content[5 + len(prefix):len(content)]
- current_channel.send(rest)
- except KeyError:
- print("Probably hit a rate limit...")
- def bond_handler(self, message):
- #Bond, James Bond.
- version = "2.5"
- change_prefix_level = 5
- generate_number_level = 15
- generate_giant_level = 60
- change_any_prefix_level = 25
- change_status_level = 60
- create_forcefield_level = 25
- suffix = "illion"
- first_numbers = ['', 'thousand', 'million', 'billion', 'trillion', 'quadrillion', 'quintillion', 'sextillion', 'septillion', 'octillion', 'nonillion']
- mono_numbers = ['','un', 'duo', 'tre', 'quattour', 'quin', 'sex', 'septen', 'octo', 'novem']
- dec_numbers = ['','dec', 'vigint', 'trigint', 'quadragint', 'quinquagint', 'sexagint', 'septuagint', 'octogint', 'nonagint']
- cent_numbers = ['', 'cent', 'ducent', 'trecent', 'quadringent', 'quingent', 'sescent', 'septingent', 'octingent', 'nongent']
- milli_numbers = ['', 'millin', 'dumill', "tremill", 'quattourmill', 'quinmill', 'sexmill', 'septenmill', 'octomill', 'novemill']
- milli_numbers_alt = ['','milli', 'dumilli', 'tremilli', 'quattourmilli', 'quinmilli', 'sexmilli', 'septenmilli', 'octomilli', "novemilli"]
- max_mod_number = 52
- max_admin_number = 1002
- tts_sent = 1
- try:
- if self.forcefields:
- pass
- except AttributeError:
- self.forcefields = []
- try:
- if self.ff_active:
- pass
- except AttributeError:
- self.ff_active = True
- self.user_data = {}
- print("Started forcefield generator.")
- self.ff_generator = Thread(target = ff_generator, args = [self] )
- self.ff_generator.start()
- if message != "":
- try:
- msg = json.loads(message) #ValueError
- except ValueError:
- msg = {"op": "-1"}
- print("NON-JSON MESSAGE: " + message)
- self.previous = msg
- if msg["op"] == 0:
- if msg["t"] == "MESSAGE_CREATE":
- event_data = msg["d"]
- content = event_data["content"]
- args = content.split(" ")
- user = discord.User(event_data["author"])
- channel = event_data["channel_id"]
- if not channel in self.channels:
- self.channels[channel] = self.discord.get_channel(channel)
- current_channel = self.channels[channel]
- channel_type = current_channel.channel_type
- if channel_type == "guild":
- if not current_channel.guild_id in self.guilds:
- self.guilds[current_channel.guild_id] = self.discord.get_guild(current_channel.guild_id)
- current_guild = self.guilds[current_channel.guild_id]
- if not os.path.exists(config_path):
- os.makedirs(config_path)
- if not os.path.isfile(config_path + "/prefix.json"):
- with open(config_path + "/prefix.json", "x") as f:
- default_prefixes = {"default": "."}
- f.write(json.dumps(default_prefixes))
- if not os.path.isfile(config_path + "/permissions.json"):
- with open(config_path + "/permissions.json", "x") as f:
- default_permissions = {
- "default": 0,
- "115659366337740809": 100}
- f.write(json.dumps(default_permissions))
- with open(config_path + "/prefix.json", "r") as f:
- prefixes = json.loads(f.read())
- with open(config_path + "/permissions.json", "r") as f:
- permissions = json.loads(f.read())
- if channel_type == "guild":
- if current_guild.id in prefixes:
- prefix = prefixes[current_guild.id]
- else:
- prefix = prefixes["default"]
- else:
- if channel_type in prefixes:
- prefix = prefixes[channel_type]
- else:
- prefix = prefixes["default"]
- try:
- if content[0:len(prefix)].lower() == prefix and user.bot == False:
- command = args[0].lower()
- command = command[len(prefix):len(command)]
- if command == "help":
- current_channel.send( "```Info: \n "
- + "This is a simple test chatbot\n"
- + "\n"
- + "Commands: \n"
- + prefix + "info | Displays bot info.\n"
- + prefix + "help | Displays help message.\n"
- + prefix + "tts <message> | Sends a tts message.\n"
- + prefix + "praise <user> | Praises user.\n"
- + prefix + "insult <user> | Insults user.\n"
- + prefix + "kill <user> | Kills user.\n"
- + prefix + "eval <math> | Does mathemagics.\n"
- + "\n"
- + prefix + "adminhelp | Admin only help message."
- + "```" )
- elif command == "info":
- current_channel.send("```James_Bond#0007 Created By Tron#0056\n"
- + "Coded in python with custom discord ( v" + discord.version + " ) and gateway ( v" + discord_gateway.version + " ) frameworks.\n"
- + "Bot version " + version + "\n"
- + "Help command: " + prefix + "help```")
- elif command == "adminhelp":
- if user.id in permissions:
- if permissions[user.id] >= 1:
- current_channel.send( "```Admin Help: \n"
- + prefix + "adminhelp | Displays Admin Help\n"
- + prefix + "setprefix <prefix> [location] | Sets prefix for location, defaults to\n"
- + prefix + "setprefix <prefix> [location] | current.\n"
- + prefix + "setlevel <user> <level> | Sets level of user to level\n"
- + prefix + "getlevel [user] | Gets level of user, defaults to self\n"
- + prefix + "setstatus <status> | Sets the bot's status.\n"
- + prefix + "giantnumber <how_big> [tts] | Creates a giant number, can display\n"
- + prefix + "giantnumber <how_big> [tts] | with tts.\n"
- + prefix + "ff <channel> <bounce to> | Created a forcefield at <channel> that\n"
- + prefix + "ff <channel> <bounce to> | bounces to <bounce to>\n"
- + prefix + "listff | Lists forcefields\n"
- + prefix + "deleteff <id> | Deletes forcefield of id <id>\n"
- + prefix + "deleteff <id> | (Warning: Changes other ff's ids.)\n"
- + "```")
- else:
- current_channel.send( "<@!" + user.id + "> Permission level 1 or above is required for this command." )
- else:
- current_channel.send( "<@!" + user.id + "> Permission level 1 or above is required for this command." )
- elif command == "eval":
- expression = content[len(args[0])+1:]
- try:
- result = eval(expression)
- except SyntaxError:
- result = "nil"
- current_channel.send(expression + " = " + str(result))
- elif command == "setprefix":
- if user.id in permissions:
- if permissions[user.id] >= change_prefix_level:
- if len(args) == 2:
- if channel_type == "guild":
- prefixes[current_guild.id] = args[1].lower()
- current_channel.send("```Set prefix for " + current_guild.name + " to " + args[1].lower() + "```")
- else:
- prefixes[channel_type] = args[1].lower()
- current_channel.send("```Set prefix for " + channel_type + "s to " + args[1].lower() + "```")
- elif len(args) >= 3 and permissions[user.id] >= change_any_prefix_level:
- prefixes[args[2]] = args[1].lower()
- current_channel.send("```Set prefix for " + args[2] + " to " + args[1].lower() + "```")
- else:
- current_channels.send("<@!" + user.id + "> Permission level " + str( change_any_prefix_level ) + " required, your level is: " + str( permissions[user.id] ) )
- with open(config_path + "/prefix.json", "w") as f:
- f.write(json.dumps(prefixes))
- else:
- current_channels.send("<@!" + user.id + "> Permission level " + str( change_prefix_level ) + " required, your level is: " + str( permissions[user.id] ) )
- else:
- current_channels.send("<@!" + user.id + "> Permission level " + str( change_prefix_level ) + " is required for this command." )
- elif command == "setstatus":
- if user.id in permissions:
- if permissions[user.id] >= change_status_level:
- self.send(3, {"idle_since": None, "game": { "name": content[ len( args[0] )+1: ] } } )
- current_channel.send("Set status to " + content[len(args[0])+1:] )
- else:
- current_channels.send("<@!" + user.id + "> Permission level " + str( change_status_level ) + " required, your level is: " + str( permissions[user.id] ) )
- else:
- current_channels.send("<@!" + user.id + "> Permission level " + str( change_status_level ) + " required, your level is: " + str( 0 ) )
- elif command == "setlevel":
- target = args[1]
- try:
- desired_level = int(args[2])
- except ValueError:
- desired_level = 0
- if target[0:3] == "<@!":
- target = target[3:len(target)-1]
- elif target[0:2] == "<@":
- target = target[2:len(target)-1]
- target_level = 0
- if target in permissions:
- target_level = permissions[target]
- if user.id in permissions:
- if permissions[user.id] > desired_level and permissions[user.id] > target_level:
- permissions[target] = desired_level
- with open(config_path + "/permissions.json", "w") as f:
- f.write(json.dumps(permissions))
- current_channel.send("Set <@!" + target + ">'s level to " + str( desired_level ) )
- elif permissions[user.id] <= desired_level:
- current_channel.send("Cannot set level higher than self.")
- elif permissions[user.id] <= target_level:
- current_channel.send("Can only set level of those lower in level.")
- else:
- current_channel.send("Insufficient permissions.")
- elif command == "ff":
- if len(args) >= 3:
- target = args[1]
- if target[0:3] == "<#!":
- target = target[3:len(target)-1]
- elif target[0:2] == "<#":
- target = target[2:len(target)-1]
- bounceback = args[2]
- if bounceback[0:3] == "<#!":
- bounceback = bounceback[3:len(bounceback)-1]
- elif bounceback[0:2] == "<#":
- bounceback = bounceback[2:len(bounceback)-1]
- else:
- pass
- if user.id in permissions:
- if permissions[user.id] >= create_forcefield_level:
- self.forcefields.append([target,bounceback, copy.deepcopy(self.user_data)])
- current_channel.send("Created forcefield at <#" + target + "> that bounces to <#" + bounceback + ">")
- else:
- current_channel.send("Permission level " + str(create_forcefield_level) + " required, your level is " + str(permissions[user.id]))
- else:
- current_channel.send("Insufficient permissions.")
- elif command == "listff":
- if user.id in permissions:
- if permissions[user.id] >= create_forcefield_level:
- to_return = ""
- ff_id = 0
- for ff in self.forcefields:
- to_return += str(ff_id) + ": <#" + ff[0] + "> bounce to <#" + ff[1] + ">\n"
- ff_id += 1
- to_return += ""
- current_channel.send(to_return)
- else:
- current_channel.send("Permission level " + str(create_forcefield_level) + " required, your level is " + str(permissions[user.id]))
- else:
- current_channel.send("Insufficient permissions.")
- elif command == "deleteff":
- if user.id in permissions:
- if permissions[user.id] >= create_forcefield_level:
- if len(args) >= 2:
- target_id = args[1]
- try:
- self.forcefields.pop(int(target_id))
- current_channel.send("Deleted forcefield of ID " + str(target_id))
- except IndexError:
- current_channel.send("That ID does not exist!")
- except TypeError:
- current_channel.send("That is not a valid ID!")
- else:
- current_channel.send("Permission level " + str(create_forcefield_level) + " required, your level is " + str(permissions[user.id]))
- else:
- current_channel.send("Insufficient permissions.")
- elif command == "getlevel":
- if len(args) >= 2:
- target = args[1]
- if target[0:3] == "<@!":
- target = target[3:len(target)-1]
- elif target[0:2] == "<@":
- target = target[2:len(target)-1]
- else:
- target = user.id
- if target in permissions:
- current_channel.send("<@!" + target + ">'s permission level is " + str( permissions[ target ] ) )
- else:
- current_channel.send("<@!" + target + ">'s permission level is " + str( 0 ) )
- elif command == "giantnumber":
- if user.id in permissions:
- if permissions[user.id] >= generate_number_level:
- if len(args) >= 2:
- if len(args) == 3:
- if args[2] == "tts":
- go_on = True
- else:
- go_on = False
- else:
- go_on = False
- try:
- how_big = int(args[1])
- if how_big > max_mod_number:
- if permissions[user.id] >= generate_giant_level:
- if how_big > max_admin_number:
- how_big = max_admin_number
- else:
- how_big = max_mod_number
- except ValueError:
- how_big = 1
- result_number = ""
- while how_big >= 1:
- how_big -= 1
- rand_number = random.randint(0,999)
- if rand_number > 0:
- if how_big < 11:
- result_number += " " + str(rand_number) + " " + first_numbers[how_big]
- elif how_big == 1001:
- result_number += " " + str(rand_number) + " " + milli_numbers[1] + suffix
- else:
- new_hb = how_big -1
- 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
- to_say = result_number.lstrip().rstrip()
- if go_on == True:
- while go_on == True:
- tts_sent += 1
- current_chunk = to_say[0:175]
- if current_chunk != "":
- if len(current_chunk) == 175:
- if current_chunk.rfind(" ") != -1:
- current_chunk = current_chunk[0:current_chunk.rfind(" ")]
- current_channel.send(current_chunk, nonce = tts_sent, tts = True)
- time.sleep(2)
- else:
- current_channel.send(current_chunk, nonce = tts_sent, tts = True)
- else:
- current_channel.send(current_chunk, nonce = tts_sent, tts = True)
- else:
- go_on = False
- print("[James_Bond] Ended number.")
- to_say = to_say[len(current_chunk):len(to_say)]
- else:
- go_on = True
- while go_on == True:
- current_chunk = to_say[0:1999]
- if current_chunk != "":
- if len(current_chunk) == 1999:
- if current_chunk.rfind(" ") != -1:
- current_chunk = current_chunk[0:current_chunk.rfind(" ")]
- current_channel.send(current_chunk, tts = False)
- time.sleep(2)
- else:
- current_channel.send(current_chunk, tts = False)
- else:
- current_channel.send(current_chunk, tts = False)
- else:
- go_on = False
- print("[James Bond] Ended number.")
- to_say = to_say[len(current_chunk):len(to_say)]
- else:
- current_channels.send("<@!" + user.id + "> Permission level " + str( generate_number_level ) + " required, your level is: " + str( permissions[user.id] ) )
- else:
- current_channels.send("<@!" + user.id + "> Permission level " + str( generate_number_level ) + " required, your level is: " + str( 0 ) )
- elif command == "tts":
- to_say = content[len(args[0])+1:]
- go_on = True
- while go_on == True:
- tts_sent += 1
- current_chunk = to_say[0:175]
- if current_chunk != "":
- if len(current_chunk) == 175:
- if current_chunk.rfind(" ") != -1:
- current_chunk = current_chunk[0:current_chunk.rfind(" ")]
- current_channel.send(current_chunk, nonce = tts_sent, tts = True)
- time.sleep(2)
- else:
- current_channel.send(current_chunk, nonce = tts_sent, tts = True)
- else:
- current_channel.send(current_chunk, nonce = tts_sent, tts = True)
- else:
- go_on = False
- print("[James_Bond] Ended tts.")
- to_say = to_say[len(current_chunk):len(to_say)]
- elif command == "praise":
- if len(args) > 1:
- target = args[1]
- else:
- if channel_type == "guild":
- users = []
- for gmember in current_guild.list_members(limit=100):
- users.append(gmember.user)
- else:
- users = [current_channel.recipient]
- target = "<@!" + random.choice(users).id + ">"
- output = random.choice(praises)
- output = output.replace("USER", target)
- output = output.replace("MASTER", "<@" + user.id + ">")
- output = output.replace("ME", "James_Bond")
- current_channel.send(output)
- elif command == "insult":
- if len(args) > 1:
- target = args[1]
- else:
- if channel_type == "guild":
- users = []
- for gmember in current_guild.list_members(limit=100):
- users.append(gmember.user)
- else:
- users = [current_channel.recipient]
- target = "<@!" + random.choice(users).id + ">"
- output = random.choice(insults)
- output = output.replace("USER", target)
- output = output.replace("MASTER", "<@" + user.id + ">")
- output = output.replace("ME", "James_Bond")
- current_channel.send(output)
- elif command == "kill":
- if len(args) > 1:
- target = args[1]
- else:
- if channel_type == "guild":
- users = []
- for gmember in current_guild.list_members(limit=100):
- users.append(gmember.user)
- else:
- users = [current_channel.recipient]
- target = "<@!" + random.choice(users).id + ">"
- output = random.choice(deaths)
- output = output.replace("USER", target)
- output = output.replace("MASTER", "<@" + user.id + ">")
- output = output.replace("ME", "James_Bond")
- current_channel.send(output)
- except KeyError:
- print("Probably hit a rate limit")
- elif msg["t"] == "GUILD_CREATE":
- for voice_state in msg["d"]["voice_states"]:
- self.user_data[voice_state["user_id"]] = voice_state
- self.user_data[voice_state["user_id"]]["guild_id"] = msg["d"]["id"]
- #print("Added " + str(self.user_data))
- elif msg["t"] == "VOICE_STATE_UPDATE":
- event_data = msg["d"]
- try:
- if self.user_data[event_data["user_id"]]:
- pass
- except KeyError:
- self.user_data[event_data["user_id"]] = event_data
- self.user_data[event_data["user_id"]].update(event_data)
- else:
- print("Got blank message")
- print("Last message was " + str(self.previous))
- self.resume()
- def ff_generator(self):
- while True:
- time.sleep(1)
- #print("Whoosh")
- #print(str(self.user_data))
- for wud in self.user_data:
- ud = self.user_data[wud]
- hack_base = {"roles":[], "joined_at": 0, "deaf": False, "mute": False, "user":{
- "id": "0",
- "username": "nil",
- "discriminator": "0000",
- "avatar": "abcabc1234567890abcdef"
- }}
- #print(str(ud))
- hack_base["user"]["id"] = ud["user_id"]
- hack_user = discord.GuildMember(hack_base,self.discord.session, ud["guild_id"])
- for ff in self.forcefields:
- if ud["user_id"] in ff[2]:
- prev_ud = ff[2][ud["user_id"]]
- if ud["channel_id"] != prev_ud["channel_id"]:
- if ud["channel_id"] == ff[0]: #If moved into ff'd channel
- hack_user.modify(channel_id = prev_ud["channel_id"])
- elif prev_ud["channel_id"] == ff[0]: #If moved away
- hack_user.modify(channel_id = ff[0])
- else:
- prev_ud["channel_id"] = ud["channel_id"]
- else: #If there is no previous user data
- hack_user.modify(channel_id = ff[1])
- def handle(self, message):
- msg = json.loads(message)
- if not os.path.isfile(auth_path):
- with open(auth_path, "x") as f:
- f.write("[\n]")
- with open(auth_path, "r") as f:
- auths = json.loads( f.read() )
- client_data = []
- num = 0
- for auth_info in auths:
- auth = auth_info["auth"]
- name = auth_info["name"]
- if name == "James_Bond":
- msg_handler = bond_handler
- elif name == "Omega-Bot":
- msg_handler = omega_handler
- else:
- msg_handler = handle
- print("Doing " + name + "'s auth with " + auth)
- try:
- if num <= 1:
- my_client = discord.Discord(auth, bot = True, user_agent = device)
- is_bot = True
- else:
- my_client = discord.Discord(auth, bot = False, user_agent = device)
- is_bot = False
- client_data.append([
- my_client,
- discord_gateway.Client(auth, num, my_client, is_bot, message_handler = msg_handler, device = device),
- num
- ])
- except UnboundLocalError:
- print(auth + " failed.")
- num += 1
- time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment