async def cmd_setliveblogs_func(message): # with open("liveblogs/" + message.server.id, 'w') as rulefile: from os import makedirs makedirs("./jobj/liveblogs/", exist_ok=True) jfileutil.save(" ".join(message.content.split(' ')[1:]), "liveblogs/" + message.server.id) await client.send_message( message.channel, "liveblogs updated. Use the liveblogs command to test.")
def downloadAllImages(username): # user_mainpage_url = "https://{}.newgrounds.com/".format(username) # user_mainpage_bs4 = BeautifulSoup(urlopen(user_mainpage_url), features="html.parser") user_artpage = getUserPage(username, "art") user_json_s = getDataJSON(user_artpage) user_json = json.loads(user_json_s) for year in user_json.get("years"): for item in user_json.get("years").get(year).get("items"): try: loom.threadWait(MAX_THREADS, 2) galleryItem = htmlToItem(item) galleryItem.preview() basepath = path.join(".", galleryItem.author) makedirs(basepath, exist_ok=True) filepath = path.join(basepath, galleryItem.name + galleryItem.ext) if not path.exists(filepath): loom.thread(target=lambda: urlretrieve(galleryItem.image, filename=filepath)) except AttributeError as e: traceback.print_exc() jobj.save(item, "item_error_{}".format(hash(item))) raise
async def cmd_setrules_func(message): # with open("rules/" + message.server.id, 'w') as rulefile: jfileutil.save(" ".join(message.content.split(' ')[1:]), "rules/" + message.server.id) await client.send_message( message.channel, "Rules updated. Use the rules command to test.")
async def loadCommands(): ############################### # Commands and command handling ############################### rbot.Command( 'test', (lambda message: client.send_message(gio, "Message")), 'Test command', # helpstr 3) # Permission Level def cmd_error_func(message): m = [1] print(m[3]) rbot.Command('error', cmd_error_func, 'Throws an error', 0) async def cmd_vote_func(message): splittoken = '; ' reaction_dict = random.choice( ['π¦π§π¨π©πͺπ«π¬π', 'β€πππππ€π', 'πΆπ°ππππΈ', 'π πππππππ']) options = ' '.join(message.content.split()[1:]).split( splittoken) # Remove first word, Create list pollmsg = await client.send_message(message.channel, "Loading...") polltext = message.author.name + " has called a vote:" i = 0 for o in options: polltext = polltext + "\n" + reaction_dict[i] + ": " + o print(reaction_dict[i]) await client.add_reaction(pollmsg, reaction_dict[i]) i = i + 1 await client.edit_message(pollmsg, new_content=polltext) rbot.Command( 'callvote', cmd_vote_func, 'List options seperated by \'; \' to prompt a vote. ', # helpstr 0) # Permission Level async def cmd_listroles_func(message): m = "" for role in message.server.roles: m += str(role.name) + ": " + str(role.id) + "\n" await client.send_message(message.author, m) rbot.Command( 'listroles', cmd_listroles_func, 'Messages you with all roles from a server', # helpstr 2) # Permission Level async def cmd_wwheek_func(message): print('wwheekin') r = urllib.request.urlopen( "https://wwheekadoodle.tumblr.com/rss").read() r = r.decode() img = random.choice(re.compile('img src="([^"]+)').findall(r)) await client.send_message(message.channel, img) rbot.Command( 'wwheek', cmd_wwheek_func, "Gets a doodle from wwheek's tumblr", # helpstr 0) # Permission Level async def cmd_sayhere_func(message): text = " ".join(message.content.split()[1:]) await client.delete_message(message) await client.send_message(message.channel, text) rbot.Command( 'sayhere', cmd_sayhere_func, 'Echos your message back where you post this command', # helpstr 3) # Permission Level async def cmd_frog_func(message): await client.send_typing(message.channel) print(len(froggos)) frogi = random.randint(1, len(froggos)) froggo = froggos[frogi - 1] await client.send_message( message.channel, "[" + str(frogi) + "/" + str(len(froggos)) + "] Frog for " + message.author.name + ": " + froggo.data['url']) await client.delete_message(message) return rbot.Command( 'frog', cmd_frog_func, 'Gives a froggo', # helpstr 0) # Permission Level rbot.Command( 'contraband', cmd_frog_func, 'Alias for frog', # helpstr 0) # Permission Level async def cmd_addfrog_func(message): global froggos msg = " ".join(message.content.split()[1:]) try: print(msg) froggos.append(rbot.Frog({'url': msg})) save_frogs() except (urllib.error.HTTPError, urllib.error.URLError, ValueError) as e: await client.send_message(message.channel, "Adding frog failed. Details in log.") traceback.print_exc(file=sys.stdout) await loadfrogs() await client.send_message(message.channel, "Added frog.") rbot.Command( 'addfrog', cmd_addfrog_func, 'Adds a frog to the frog dictionary', # helpstr 2) # Permission Level async def cmd_removefrog_func(message): global froggos msg = " ".join(message.content.split()[1:]) try: i = 0 for frog in froggos: if frog.data['url'] == msg: froggos.remove(frog) i += 1 save_frogs() except (urllib.error.HTTPError, urllib.error.URLError) as e: await client.send_message( message.channel, "Check failed! Bad link? Details in log. Ignore this message if the link came from discord, or if the image shows up anyway." ) traceback.print_exc(file=sys.stdout) return await loadfrogs() await client.send_message(message.channel, "Removed " + str(i) + " occurances of frog.") rbot.Command( 'removefrog', cmd_removefrog_func, 'Removes a frog from the frog dictionary', # helpstr 2) # Permission Level async def cmd_listemotes_func(message): m = "" for s in message.server.emojis: m += s.name + "\t" + s.id + "\t" + s.url + "\n" await rutil.send_message_smart(message.author, m) rbot.Command( 'listemotes', (cmd_listemotes_func), 'Messages you the server\'s emotes', # helpstr 1) # Permission Level async def cmd_pm_func(message): for m in message.mentions: target = m if target is None: await client.send_message(message.channel, "No such person") break content = " ".join(message.content.split()[1:]) await client.send_message(target, content) await client.delete_message(message) rbot.Command( 'pm', cmd_pm_func, 'Sends a PM to one person mentioned', # helpstr 3) # Permission Level async def cmd_restart_func(message): await client.change_presence(game=discord.Game(name="swords", type=1)) try: await client.add_reaction( message, await emote(message.server, 'smolrubes', False)) except: pass rutil.eprint("Restarting rubybot at request of " + message.author.name) with open("last_trace.log", "w") as f: f.write("Restarted at request of " + message.author.name) f.flush() sys.exit(0) rbot.Command( 'restart', cmd_restart_func, 'Restarts rubybot', # helpstr 2) # Permission Level rbot.Command( 'reload', cmd_restart_func, 'Alias of restart', # helpstr 2) async def cmd_permissions_func(message): p = rbot.permissionLevel(message.author, message.server) pss = ['Everyone', 'Moderator', 'Admin', 'Super Admin'] ps = pss[p] await client.send_message( message.channel, message.author.name + ", your permission level in this server is " + str(p) + " (" + ps + ")") rbot.Command( 'permissions', cmd_permissions_func, 'Tells you your permissions level in context', # helpstr 0) # Permission Level async def cmd_roll_func(message): dice = " ".join(message.content.split()[1:]) bonus = 0 drops = 0 try: if "+" in dice: dice, bonus = map(str, dice.split(' +')) if "droplowest" in dice: dice, drops = map(str, dice.split(' droplowest ')) elif "-" in dice: dice, drops = map(str, dice.split(' -')) rolls, limit = map(int, dice.split('d')) except Exception: await client.send_message( message.channel, "I don't understand that dice notation! The format is NdN +N") return bonus = int(bonus) drops = int(drops) if rolls + limit > 200: await client.send_message( message.channel, "Hey, I'm really sorry " + message.author.mention + ", but I can't do that in my head. :c") return result = rollplain(rolls, limit) resultsstr = ', '.join(str(result[r]) for r in range(rolls)) if rolls > 1: total = totalDelimitedList(result, drops) await client.send_message( message.channel, message.author.mention + "'s roll:\n" + resultsstr + "\nTotal: " + str(total) + "+ " + str(bonus) + " = " + str(total + bonus)) else: await client.send_message( message.channel, message.author.mention + "'s roll:\n" + resultsstr + " + " + str(bonus) + " = " + str(result[0] + bonus)) if ((rolls == 4) and (limit == 20)) or (rolls == 69) or (limit == 69): await client.send_message(message.channel, "you meme-loving degenerates.") rbot.Command( 'roll', cmd_roll_func, 'Rolls fancy dice', # helpstr 0) # Permission Level async def cmd_reteam_func(message): msg = " ".join(message.content.split()[1:]) taboo_server = rbot.servers['245789672842723329'].server taboo_teams = [ discord.utils.get(taboo_server.roles, id=teamid) for teamid in jfileutil.load("altgen_teams") ] targets = message.mentions if msg.lower() == "all": targets = message.server.members for target in targets: newteam = taboo_teams[int(target.id) % len(taboo_teams)] await client.add_roles(target, newteam) for role in taboo_teams: # await client.send_message(message.channel, "Checking role " + role.name) if (role in target.roles) and (role is not newteam): # await client.send_message(message.channel, "Removing role " + role.name) await client.remove_roles(target, role) if msg.lower() != "all": await client.send_message( message.channel, "Please welcome " + target.mention + " to " + newteam.name) await client.delete_message(message) rbot.Command( 'reteam', cmd_reteam_func, 'Re-teams a member on taboo', # helpstr 2) # Permission Level async def cmd_smolmote_func(message): msg = message.content.split() try: chan = client.get_channel(msg[1]) await client.send_message( chan, await emote(chan.server, 'smolrubes', True)) except AttributeError: await client.send_message(message.author, "No such channel as " + msg[1]) rbot.Command( 'smol', cmd_smolmote_func, 'Sends a smol to channel by ID', # helpstr 3) # Permission Level async def cmd_nickname_func(message): nickname = " ".join(message.content.split()[1:]) await client.change_nickname(rbot.servers[message.server.id].member, nickname) rbot.Command( 'nick', cmd_nickname_func, 'Changes nickname', # helpstr 3) # Permission Level async def cmd_avatar_func(message): msg = " ".join(message.content.split()[1:]) try: with open(msg, 'rb') as fp: await client.edit_profile(avatar=fp.read()) except: await client.send_message(message.author, traceback.format_exc()) rbot.Command( 'avatar', cmd_avatar_func, 'Sets avatar', # helpstr 3) # Permission Level async def cmd_sayat_func(message): # TODO: Gotta localize the emotes msg = message.content.split() try: await client.send_message(client.get_channel(msg[1]), " ".join(msg[2:])) except discord.errors.InvalidArgument: await client.send_message(message.author, "No such channel as " + msg[1]) rbot.Command( 'say', cmd_sayat_func, 'Says a message at a channel by ID', # helpstr 3) # Permission Level async def cmd_hardreboot_func(message): await client.send_message(message.author, "Here goes!") await client.send_message(message.author, os.system("sudo reboot")) rbot.Command( 'hardreboot', cmd_hardreboot_func, 'sudo reboot', # helpstr 3) # Permission Level async def cmd_help_func(message): helpstrs = [] if message.server: for command in rbot.servers[message.server.id].commands: if rbot.permissionLevel(message.author, message.server) >= command.permlevel: helpstrs += [ "!**" + command.name + "** : " + command.helpstr ] helpstrs = sorted(helpstrs) helpstrs.insert( 0, message.author.name + "'s list of availible commands (in context):") await rutil.send_message_smart(message.channel, "\n".join(helpstrs)) else: for command in rbot.direct_commands: if rbot.permissionLevel(message.author, message.server) >= command.permlevel: helpstrs += [ "!**" + command.name + "** : " + command.helpstr ] helpstrs = sorted(helpstrs) await rutil.send_message_smart(message.author, "\n".join(helpstrs)) rbot.Command( 'help', cmd_help_func, 'List availible commands and their functions', # helpstr 0) # Permission Level async def cmd_allhelp_func(message): helpstrs = [] if message.server: for command in rbot.servers[message.server.id].commands: helpstrs += [ "(" + str(command.permlevel) + ") !" + command.name + " : " + command.helpstr ] helpstrs = sorted(helpstrs) helpstrs.insert( 0, message.author.name + "'s list of availible commands (in context):") await rutil.send_message_smart(message.channel, "\n".join(helpstrs)) else: helpstr = "" for command in rbot.direct_commands: helpstr += [ "(" + str(command.permlevel) + ") !" + command.name + " : " + command.helpstr ] await rutil.send_message_smart(message.author, helpstr) rbot.Command( 'allhelp', cmd_allhelp_func, 'List all commands and their permission level', # helpstr 1) # Permission Level def getRules(server): try: return jfileutil.load("rules/" + server.id) except FileNotFoundError: return "The server owner has not set rules. Do so with !setrules" async def cmd_rules_func(message): await rutil.send_message_smart(message.channel, getRules(message.server)) rbot.Command( 'rules', cmd_rules_func, 'Lists the server\'s rules', # helpstr 0) # Permission Level async def cmd_rulesmd_func(message): await rutil.send_message_smart( message.channel, "```" + getRules(message.server) + "```") rbot.Command( 'mdrules', cmd_rulesmd_func, 'Lists the server\'s rules, in plaintext.', # helpstr 1) # Permission Level async def cmd_setrules_func(message): # with open("rules/" + message.server.id, 'w') as rulefile: jfileutil.save(" ".join(message.content.split(' ')[1:]), "rules/" + message.server.id) await client.send_message( message.channel, "Rules updated. Use the rules command to test.") rbot.Command( 'setrules', cmd_setrules_func, 'Modifies the server\'s rules', # helpstr 2) # Permission Level def getliveblogs(server): try: return jfileutil.load("liveblogs/" + server.id) except FileNotFoundError: return "The server owner has not set liveblogs. Do so with !setliveblogs" async def cmd_liveblogs_func(message): await rutil.send_message_smart(message.channel, getliveblogs(message.server)) rbot.Command( 'liveblogs', cmd_liveblogs_func, 'Lists the server\'s liveblogs', # helpstr 0) # Permission Level async def cmd_liveblogsmd_func(message): await rutil.send_message_smart( message.channel, "```" + getliveblogs(message.server) + "```") rbot.Command( 'mdliveblogs', cmd_liveblogsmd_func, 'Lists the server\'s liveblogs, in plaintext.', # helpstr 1) # Permission Level async def cmd_setliveblogs_func(message): # with open("liveblogs/" + message.server.id, 'w') as rulefile: from os import makedirs makedirs("./jobj/liveblogs/", exist_ok=True) jfileutil.save(" ".join(message.content.split(' ')[1:]), "liveblogs/" + message.server.id) await client.send_message( message.channel, "liveblogs updated. Use the liveblogs command to test.") rbot.Command( 'setliveblogs', cmd_setliveblogs_func, 'Modifies the server\'s liveblogs', # helpstr 2) # Permission Level async def cmd_pins_func(message): await client.send_typing(message.channel) pins = await list( client.logs_from(client.get_channel('278819870106451969'), limit=400)) pinmsg = random.choice(list(pins)) pinurl = pinmsg.content for a in pinmsg.attachments: pinurl += "\n" + a.get('url') await client.send_message( message.channel, "Pin from " + pinmsg.author.name + " from " + str(pinmsg.timestamp) + ": " + pinurl) await client.delete_message(message) rbot.Command( 'pins', cmd_pins_func, 'Posts a random pinned message', # helpstr 0) # Permission Level async def cmd_bad_func(message): source = message.author for target in message.mentions: if target is None: await client.send_message(message.channel, "No such person") await client.delete_message(message) return if source is None: source = message.server.Client badr = discord.utils.get(message.server.roles, id='388739766025191435') verified = discord.utils.get(message.server.roles, id='388737413213716481') i = 1 while (badr not in target.roles): i = i + 1 await client.add_roles(target, badr) while (verified in target.roles): i = i + 1 await client.remove_roles(target, verified) await client.send_message( message.channel, target.name + " has been badded to the pit by " + source.name + ".") # await client.send_message(modchat, "Log: " + target.name + " has been badded to the pit by " + source.name) await client.delete_message(message) rbot.Command( 'bad', cmd_bad_func, 'Bad them to the pit!', # helpstr 1) # Permission Level async def cmd_unbad_func(message): source = message.author for target in message.mentions: if target is None: await client.send_message(message.channel, "No such person") await client.delete_message(message) return badr = discord.utils.get(message.server.roles, id='388739766025191435') verified = discord.utils.get(message.server.roles, id='388737413213716481') # await client.remove_roles(target, badr) i = 1 while (badr in target.roles): i = i + 1 await client.remove_roles(target, badr) while (verified not in target.roles): i = i + 1 await client.add_roles(target, verified) # await client.send_message(workingChan, target.name + " has been unbadded by " + source.name) await client.send_message( message.channel, "Log: " + target.name + " has been unbadded by " + source.name + ".") await client.delete_message(message) rbot.Command( 'unbad', cmd_unbad_func, 'unBad them from the pit!', # helpstr 1) # Permission Level async def cmd_pronoun_func(message): await client.send_message( message.channel, "This function has been replaced by !togglerole.") # pronoun = " ".join(message.content.split()[1:]) # r_him = discord.utils.get( # message.server.roles, id='388740839943438336') # r_her = discord.utils.get( # message.server.roles, id='388740921975373835') # r_they = discord.utils.get( # message.server.roles, id='388740870641287169') # if ((pronoun.upper() == "HIM") or (pronoun.upper() == "HE") or (pronoun.upper() == "MALE") or (pronoun.upper() == "MAN") or (pronoun.upper() == "M") or (pronoun.upper() == "H")): # role = r_him # if ((pronoun.upper() == "HER") or (pronoun.upper() == "SHE") or (pronoun.upper() == "FEMALE") or (pronoun.upper() == "WOMAN") or (pronoun.upper() == "F") or (pronoun.upper() == "S")): # role = r_her # if ((pronoun.upper() == "THEM") or (pronoun.upper() == "THEY") or (pronoun.upper() == "IT") or (pronoun.upper() == "OTHER") or (pronoun.upper() == "T")): # role = r_they # try: # if role in message.author.roles: # await client.send_message(message.author, "You already had the role " + role.name + ", so I'm toggling it off. ") # rutil.eprint(message.author.name + " has role " + # role.name + ", removing.") # await client.remove_roles(message.author, role) # else: # if role not in message.author.roles: # await client.send_message(message.author, "You did not have the role " + role.name + ", so I'm adding it now for you!") # rutil.eprint(message.author.name + # " does not have role " + role.name + ", adding.") # await client.add_roles(message.author, role) # except BaseException as e: # await client.send_message(message.author, "Either you did not specify a pronoun, or I don't know what you mean by " + pronoun + ". Sorry! If you think this is an error, please report it. ") # await client.delete_message(message) rbot.Command( 'pronoun', cmd_pronoun_func, 'Depreciated.', # helpstr 0) # Permission Level async def cmd_togglerole_func(message): requested = " ".join(message.content.split()[1:]) try: freeroles = jfileutil.load("freeroles/" + message.server.id) except FileNotFoundError: await client.send_message( message.channel, "This server has no free roles, or else something is misconfigured." ) roleLookup = freeroles.get(requested) if roleLookup is None: await client.send_message( message.channel, "That role name is unknown! Availible roles:") await client.send_message( message.channel, "\n".join(["`" + k + "`" for k in freeroles.keys()])) else: role = discord.utils.get(message.server.roles, id=roleLookup) if role in message.author.roles: await client.remove_roles(message.author, role) await client.send_message( message.author, "You already had the role " + role.name + ", so I'm toggling it off. ") rutil.eprint(message.author.name + " has role " + role.name + ", removing.") else: if role not in message.author.roles: await client.add_roles(message.author, role) await client.send_message( message.author, "You did not have the role " + role.name + ", so I'm adding it now for you!") rutil.eprint(message.author.name + " does not have role " + role.name + ", adding.") rbot.Command( 'togglerole', cmd_togglerole_func, 'Toggles roles.', # helpstr 0) # Permission Level async def cmd_verify_func(message): workingChan = client.get_channel('388730628176084992') verified = discord.utils.get(message.server.roles, id='388737413213716481') for member in message.mentions: if verified not in member.roles: await client.add_roles(member, verified) await client.send_message(message.channel, "Verified user " + member.name) else: await client.send_message( message.channel, "User is already verified: " + member.name) await client.send_message( workingChan, "Please welcome new user " + member.mention + " to the server!") await client.delete_message(message) rbot.Command( 'verify', cmd_verify_func, 'Verifies a user', # helpstr 1) # Permission Level async def cmd_fund_func(message): await client.send_message( message.channel, embed=discord.Embed(title="Keep me alive and keep Gio healthy!", url="https://www.patreon.com/giovan"). set_author(name="Giovan").set_thumbnail( url="https://cdn.discordapp.com/emojis/361958691244867584.png") ) rbot.Command( 'fund', cmd_fund_func, 'Gives information about patreon', # helpstr 0) # Permission Level rbot.Command( 'patreon', cmd_fund_func, 'Alias for fund', # helpstr 0) # Permission Level async def cmd_frig_func(message): await client.send_message( message.channel, "http://www.qwantz.com/comics/comic2-1348.png") rbot.Command( 'frig', cmd_frig_func, 'like, frig, man!', # helpstr 0) # Permission Level # async def cmd__func(message): # cmd_ = rbot.Command('', cmd__func, # '', # helpstr # 0) # Permission Level cmdlist_base = [ rbot.commands['allhelp'], rbot.commands['avatar'], rbot.commands['callvote'], rbot.commands['frig'], rbot.commands['frog'], rbot.commands['fund'], rbot.commands['help'], rbot.commands['listemotes'], rbot.commands['listroles'], rbot.commands['rules'], rbot.commands['mdrules'], rbot.commands['setrules'], rbot.commands['liveblogs'], rbot.commands['mdliveblogs'], rbot.commands['setliveblogs'], rbot.commands['nick'], rbot.commands['patreon'], rbot.commands['permissions'], rbot.commands['reload'], rbot.commands['removefrog'], rbot.commands['restart'], rbot.commands['roll'], rbot.commands['sayhere'], rbot.commands['togglerole'] ] cmdlist_util = [ rbot.commands['test'], rbot.commands['error'], rbot.commands['say'], rbot.commands['smol'], rbot.commands['hardreboot'] ] for server in rbot.servers.values(): server.add_cmds(cmdlist_base) try: cmdlist = jfileutil.load("cmds/" + server.server.id) server.add_cmds([rbot.commands[key] for key in cmdlist]) server.add_cmds([ rbot.commands[key] for key in ["liveblogs", "mdliveblogs", "setliveblogs"] ]) except FileNotFoundError: m = "I am missing a command list for server " + \ server.server.name + " with id " + server.server.id await client.send_message(gio, m) jfileutil.save([], "cmds/" + server.server.id) print(m) rbot.direct_commands = list(cmdlist_base + cmdlist_util)
def save_frogs(): global froggos froggos = sorted(list(set(froggos))) jfileutil.save([f.data for f in froggos], "frogsmd5")
def saveWhois(whoisData): print("Saving whois cache with " + str(len(whoisData["ips"])) + " entries") j.save(whoisData, cachefilename)