async def vpn_multi(self, ctx): response = officialEmbed(title=s_faq["vpnmulti"][0]) response.set_thumbnail(url=(img_openvpn)) for i in range(1, len(s_faq["vpnmulti"])): response.add_field(name="• Step " + str(i), value=s_faq["vpnmulti"][i]) await ctx.send(embed=response)
async def dark(self, ctx): darkQuotes = config.get_string("quotes")["dark"] quote = darkQuotes[random.randint(0, len(darkQuotes)-1)] if quote == "buttdance": buttdance = self.bot.get_emoji(config.get_config("emotes")["buttdance"]) quote = str(buttdance) response = officialEmbed(title=quote, color=0xff4500, author="DarkStar7471", author_img="https://i.imgur.com/jZ908d1.png", footer="") await ctx.send(embed=response)
async def dark(self, ctx): darkF = json.loads(open("config/dark.json", "r").read()) darkQuotes = darkF["quotes"] quote = darkQuotes[random.randint(0, len(darkQuotes) - 1)] response = officialEmbed(title=quote, color=0xff4500, author="DarkStar7471", author_img="https://i.imgur.com/jZ908d1.png", footer="") await ctx.send(embed=response)
async def lookup(self, ctx, *arg): arg = ' '.join(arg) self.conn = database.connect_to_db() # Token-based search check if token_regex.match(arg): match_type = 'token' db_result = database.get_user_by_thm_token(self.conn, arg) else: # ID-based search checks if mention_regex.match(arg): match_type = 'mention' user_id = mention_regex.search(arg).group(1) elif user_id_regex.match(arg): match_type = 'user id' user_id = arg elif user_discrim_regex.match(arg): match_type = 'user#discrim' user = self.bot.get_guild(id_guild).get_member_named(arg) if user is None: return await ctx.send(f"Failed to find a user with that discriminator") user_id = user.id else: return await ctx.send(s_lookup["match_failed"]) try: db_result = database.get_user_by_discord_uid(self.conn, user_id) except: return await ctx.send(s_lookup["db_fetch_failed"]) # Loops over the results (also handles multiple-row results if they occur) for row in db_result: u_id, u_token = row try: thm_user = get_user_by_token(u_token) except: return await ctx.send(s_lookup["thm_fetch_failed"]) response = officialEmbed("Token match", footer=f"Matched with {match_type}") response.add_field(name="Discord mention", value=f"<@{u_id}>") response.add_field(name="Discord ID", value=u_id) response.add_field(name="THM username", value=thm_user["username"]) response.add_field(name="THM profile", value=thm_user_link.format(thm_user["username"])) response.add_field(name="THM token", value=u_token) await ctx.send(embed=response) if len(db_result) == 0: if ctx.author.id == 650476435269484549: await ctx.send("No results. Are you happy Muirland? I made another modification in prod.") else: await ctx.send("No results.")
async def skidy(self, ctx): message = ":slight_smile:" if random.randint(0,1) >= 0.5: skidy_gif = self.bot.get_emoji(config.get_config("emotes")["skidygif"]) message = str(skidy_gif) response = officialEmbed(title=message, color=0x225999, author="Skidy", author_img="https://i.imgur.com/fSMnXPt.png", footer="") await ctx.send(embed=response)
async def uptime(ctx): # Gets the time and substracts it to the current time. current_time = time.time() difference = int(round(current_time - start_time)) text = str(datetime.timedelta(seconds=difference)) # Embed. embed = officialEmbed(color=0x3289a8) embed.add_field(name="Uptime", value=text) # Sends. await ctx.channel.send(embed=embed)
async def xkcd(self, ctx): comic_no = random.randint(1, 1900) url = f"http://xkcd.com/{comic_no}/info.0.json" data = await api_fetch(url) img = data.get("img") title = data.get("title") alt = data.get("alt") response = officialEmbed(color=0xffb6b9, footer="From the XKCD Official API!") response.add_field(name=title, value=alt) response.set_image(url=img) await ctx.send(embed=response)
async def convertissues(self, ctx): if ctx.channel.id != c_cl: return response = officialEmbed() response.add_field(name=s_faq["convertissues"][0], value=s_faq["convertissues"][1]) for i in range(2, len(s_faq["convertissues"])): if i == 4: response.add_field(name="• Fix "+str(i - 1), value=s_faq["convertissues"][i], inline=True) continue response.add_field(name="• Fix "+str(i - 1), value=s_faq["convertissues"][i]) #response.add_field(name="Website: ", value=s_faq["convertissues"][6]) await ctx.send(embed=response)
async def random_room(self, ctx): room = get_random_room() response = officialEmbed(room['title'], room['description']) response.set_thumbnail(url=room['image']) response.add_field(name="Room type", value=room['type'].capitalize(), inline=True) response.add_field(name="Difficulty", value=room['difficulty'].capitalize(), inline=True) response.add_field(name="Upvotes", value=room['upVotes'], inline=True) response.add_field(name="Sub required", value=bool_to_yesno(not room['freeToUse']), inline=True) response.add_field(name="Room creator", value=room['creator'], inline=True) response.url = f"{c_join_room}{room['code']}" await ctx.send(embed=response)
async def xkcd(self,ctx): comic_no = random.randint(1,1900) url = f"http://xkcd.com/{comic_no}/info.0.json" async with aiohttp.ClientSession() as session: async with session.get(url) as data: new_data = await data.read() json_data = json.loads(new_data) img = json_data.get("img") title = json_data.get("title") alt = json_data.get("alt") response = officialEmbed(color=0xffb6b9, footer="From the XKCD Official API!") response.add_field(name=title,value=alt) response.set_image(url=img) await ctx.send(embed=response)
async def gtfobins(self, ctx, search_term=""): if sanitize_check(search_term) == False: await ctx.send(s_not_sanitized) gtfobins_file = json.loads(open(c_file_gtfobins, "r").read()) # If user is searching for something. if search_term != "": try: # Getting data. data = gtfobins_file[search_term] result = "".join(["- " + item[1:-1] + "\n" for item in data]) # Generating the embed. response = officialEmbed( s_gfto["result_title"].format(search_term), color=0xcc0000) response.set_thumbnail(url=s_gfto["logo"]) response.add_field(name=s_gfto["search_terms"], value=search_term) response.add_field(name=s_gfto["vulnerability"], value=result) response.add_field( name=s_gfto["url"], value="https://gtfobins.github.io/gtfobins/" + search_term) await ctx.send(embed=response) except Exception as e: await ctx.send(s_gfto["not_found"].format(search_term)) # Otherwise display a list of possibilities. else: try: result = "" for key, value in gtfobins_file.items(): result += "- " + key result += "\n" response = discord.Embed(title=s_gfto["binaries"], color=0xcc0000) response.set_thumbnail(url=s_gfto["logo"]) response.add_field(name=s_gfto["binaries_list"], value=result) response.add_field(name="How to?", value=s_gfto["howto"]) await ctx.send(s_gfto["sending_list"]) await ctx.send(embed=response) except Exception as e: await ctx.send(s_gfto["error"])
async def send(channel, json_data): # Set up embed. img = json_data[0]["image"] title = json_data[0]["title"] code = "http://tryhackme.com/room/" + json_data[0]["code"] description = json_data[0]["description"] embed = officialEmbed(title, description) embed.set_image(url=img) # Send messages. await channel.send("A new room is available! | Check it out: " + code, embed=embed) # Updates local file. with open("config/room.json", "w") as file: json.dump(json_data, file)
async def rules(self, ctx): # Make embed. response = officialEmbed("Rules", color=0xffff00) response.set_thumbnail(url="https://tryhackme.com/img/THMlogo.png") # Load the rules from config. rulesF = json.loads(open("config/rules.json", "r").read()) rules = rulesF["rules"] i = 0 # Add each rule. for rule in rules: response.add_field(name=(str(i + 1) + "."), value=rule) i = i + 1 # Send. await ctx.send(embed=response)
async def send_rules(channel): """Makes the embed with all the rules and sends it.""" # Make embed. response = officialEmbed("Rules", color=0xffff00) response.set_thumbnail(url=config.get_config("info")["logo"]) # Load the rules from config. i = 0 # Add each rule. for rule in rules: response.add_field(name=(str(i+1)+"."), value=rule) i = i + 1 # Send. await channel.send(embed=response)
async def send_verify(channel): """Sends the instructions on how to verify yourself.""" # Embed making. response = officialEmbed("How to get verified?") response.set_thumbnail(url=config.get_config("info")["logo"]) # Loading text from JSON. steps = config.get_string("faq")["verify"] i = 0 # Add each step to the embed. for step in steps: response.add_field(name=("Step "+str(i+1)), value=step) i = i + 1 # Sending the created embed in DM to the user. await channel.send(embed=response)
async def multivpn(self, ctx): response = officialEmbed() response.set_thumbnail(url="https://tryhackme.com/room/openvpn") response.add_field( name="• Step 1", value= "Type ps aux | grep openvpn into your terminal and press enter") response.add_field( name="• Step 2", value= "If there's more than one line (and the second doesn't have \"grep\" in it), do the following steps" ) response.add_field( name="• Step 3", value="Type killall openvpn into your terminal and press enter") response.add_field( name="• Step 4", value="Start the VPN with sudo openvpn <path-to-config>") await ctx.send(embed=response)
async def giveaway_stop(self, ctx, _id, gDesc): if ctx.author.id == 170810389406285824 or ctx.author.id == 174276690699091968 or ctx.author.id == 650476435269484549: chan_announcement = self.bot.get_channel(id_announcements) gResult = (await chan_announcement.fetch_message(_id)).reactions[0] embed = officialEmbed("Giveaway results", gDesc) # Retrives the winner, excluding the BOT. winner = None users = await gResult.users().flatten() while winner == None or winner.id == self.bot.user.id: winner = random.choice(users) embed.add_field(name=s_giveaway["announce_field_title"], value=s_giveaway["announce_field_value"].format( winner.mention)) await chan_announcement.send(embed=embed)
async def announce_room(channel, json_data, code=None): """Announces a room using its data.""" # Set up embed. img = json_data["image"] title = json_data["title"] if code == None: url = c_url_room["room"] + str(json_data["code"]) else: url = c_url_room["room"] + code description = json_data["description"] embed = officialEmbed(title, description) embed.set_image(url=img) # Send messages. await channel.send(s_room["newroom"].format(url), embed=embed) # Updates local file. with open(c_room_data, "w") as file: json.dump(json_data, file)
async def giveaway_output(self, data): """Handle the end of a giveaway given its data. (Announces winner, reset persistance, etc)""" deltaTime = datetime.strptime(data["ending_time"], "%Y-%m-%dT%H:%M:%S.%f") - datetime.now() gTimeSec = int(deltaTime.total_seconds()) gDesc = data["desc"] gMessageId = data["message_id"] # Waits... # We check that the time is actually in the future. if gTimeSec > 0: await asyncio.sleep(gTimeSec) # Sends results. try: chan_announcement = self.bot.get_channel(id_announcements) gResult = ( await chan_announcement.fetch_message(gMessageId)).reactions[0] embed = officialEmbed("Giveaway results", gDesc) # Retrives the winner, excluding the BOT. winner = None users = await gResult.users().flatten() while winner == None or winner.id == self.bot.user.id: winner = random.choice(users) embed.add_field(name=s_giveaway["announce_field_title"], value=s_giveaway["announce_field_value"].format( winner.mention)) await chan_announcement.send(embed=embed) except: print(s_giveaway["canceled"]) # Giveaway is finished, erase JSON data. clear_file()
async def rank_from_id(self, ctx, id): """Retrieve a user's rank from his ID.""" db = database.connect_to_db() request = database.get_user_by_discord_uid(db, id) if len(request) == 0: response = officialEmbed("Rank", s_userrank["user_not_found"], color=0xdc143c) userImg = config.get_config("info")["icon"] response.set_thumbnail(url=userImg) await ctx.send(embed=response) else: user_token = request[0][1] data = await api_fetch(c_api_token, user_token) user = data["username"] await self.send_rank(ctx, user)
async def writeup(self, ctx, room_code): # Request to the API. async with aiohttp.ClientSession() as session: async with session.get(api_url + "room/" + room_code) as new_data: text = await new_data.read() json_data = json.loads(text) # If the specified code is wrong. if json_data["success"] == False: botMsg = await ctx.send("Sorry, but the room code ``" + room_code + "`` could not be found.") time.sleep(5) await botMsg.delete() await ctx.message.delete() return # If there is no writeup. if len(json_data["writeups"]) == 0: await ctx.send("Sorry, there is no writeup for this room.") return # Set up embed. img = json_data["image"] title = json_data["title"] link = "http://tryhackme.com/room/" + room_code embed = officialEmbed(title, link) embed.set_image(url=img) for wu in json_data["writeups"]: embed.add_field(name="By: " + wu["username"], value=wu["link"]) # Send messages. await ctx.send(embed=embed)
async def wiki(self, ctx, *, search): try: api_url = "https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=" + search async with aiohttp.ClientSession() as session: async with session.get(api_url) as data: # Request. data = await data.read() data = json.loads(data)['query']['pages'] data = next(iter(data.values())) # Get the data. title = data['title'] content = data['extract'].split(".") # Embed. response = officialEmbed( color=0xffffff, footer="From the Wikipedia Official API!") response.add_field(name=title, value=''.join(content[:2])) await ctx.send(embed=response) except: await ctx.send("Some Error Occured!")
async def giveaway(self, ctx): gDesc = "" gReac = None gTimeHour = 0 # Remove the command. await ctx.message.delete() # Check for the user to be admin. if not hasRole(ctx.author, adminID): botMsg = await ctx.send( "You do not have the permission to do that.") time.sleep(5) await botMsg.delete() return # Check for the author. def checkAuth(m): return m.author == ctx.author def checkDone(m): return (m.author == ctx.author and m.content.lower() == "done") botMsgCancel = await ctx.send( "Enter CANCEL at anytime to cancel the giveaway.") # Retrieve the giveaway's description. botMsg = await ctx.send( "Please provide a description for the giveaway:") gDescMsg = await self.bot.wait_for('message', check=checkAuth) gDesc = gDescMsg.content await botMsg.delete() await gDescMsg.delete() if gDescMsg.content.lower() == "cancel": await botMsgCancel.delete() confirmDelMsg = await ctx.send("Giveaway canceled.") time.sleep(5) await confirmDelMsg.delete() return # Getting the reaction to enter the giveaway. botMsgText = "Now please react to this message with the reaction users should use to enter giveaway. Then send DONE." botMsg = await ctx.send(botMsgText) # Waits for the reaction and DONE message. isDone = False while not isDone: msg = await self.bot.wait_for('message', check=checkAuth) if msg.content.lower() == "cancel": await botMsgCancel.delete() await botMsg.delete() await msg.delete() confirmDelMsg = await ctx.send("Giveaway canceled.") time.sleep(5) await confirmDelMsg.delete() return # Checks if the amount of emojis matches the amount of options. ## We need to re-cache the message to retrieve the reactions. cacheBotMsg = await ctx.channel.fetch_message(botMsg.id) if len(cacheBotMsg.reactions) != 1: await msg.delete() errorMsg = await ctx.send( "Only one reaction allowed, please fix it and send DONE.") time.sleep(5) await errorMsg.delete() else: isDone = True reaction = cacheBotMsg.reactions[0] # Asigns reaction. gReac = reaction.emoji # Clears msg. await botMsg.delete() await msg.delete() # Gets the time the giveaway should last. isDone = False while (not isDone): timeAsk = await ctx.send("Time the giveaway should last in hours:") msg = await self.bot.wait_for('message', check=checkAuth) if msg.content.lower() == "cancel": await botMsgCancel.delete() await msg.delete() await timeAsk.delete() confirmDelMsg = await ctx.send("Giveaway canceled.") time.sleep(5) await confirmDelMsg.delete() return try: gTimeHour = int(msg.content) isDone = True except: errorMsg = await ctx.send("Numbers only, please retry.") time.sleep(2) await errorMsg.delete() isDone = False finally: await timeAsk.delete() await msg.delete() # Confirmation embed. embed = officialEmbed("This is the giveaway you are about to create:", gDesc, footer="Lasting for " + str(gTimeHour) + " hour(s).") embed.add_field(name="Enter-giveaway reaction", value=gReac) # Sends embed. botEmbed = await ctx.send(embed=embed) # Asks for validation. botMsg = await ctx.send( "To confirm enter ***yes*** or anything else to cancel. (not case sensitive)" ) giveawayValid = await self.bot.wait_for('message', check=checkAuth) # Checks validation's answer. if not giveawayValid.content.lower() == "yes": cancelMsg = await ctx.send("You canceled the giveaway.") # Removes useless msg. await botMsgCancel.delete() await botEmbed.delete() await botMsg.delete() await giveawayValid.delete() await cancelMsg.delete() else: # Removes useless msg. await botMsgCancel.delete() await botMsg.delete() await giveawayValid.delete() # Makes embed. embed = officialEmbed("Giveaway", gDesc) embed.add_field(name="Enter-giveaway reaction", value=gReac) # Sends the giveaway. announcementChan = self.bot.get_channel(channelID) gEmbed = await announcementChan.send(embed=embed) # Adds the reactions to it. await gEmbed.add_reaction(gReac) # Waits... time.sleep(15) #time.sleep(gTimeHour*60*60) # Sends results. # try: gResult = (await announcementChan.fetch_message(gEmbed.id)).reactions[0] embed = officialEmbed("Giveaway results", gDesc) # Retrives the winner, excluding the BOT. winner = None users = await gResult.users().flatten() while winner == None or winner.id == self.bot.user.id: winner = random.choice(users) embed.add_field(name="Winner is", value=winner.mention + ", congratulations!") await announcementChan.send(embed=embed)
async def spaniel(self, ctx): response = officialEmbed("Spaniel", color=0xff4500) response.set_image( url="https://www.about-cocker-spaniels.com/images/cute-puppy-names-boys-1.jpg") await ctx.send(embed=response)
async def giveaway(self, ctx): gDesc = "" gReac = None gTimeHour = 0 # Remove the command. await ctx.message.delete() # Check for the user to be admin. if not has_role(ctx.author, id_admin): botMsg = await ctx.send(s_no_perm) await asyncio.sleep(5) await botMsg.delete() return # Check for the author. def checkAuth(m): return m.author == ctx.author def checkDone(m): return (m.author == ctx.author and m.content.lower() == s_giveaway["confirm_word"]) botMsgCancel = await ctx.send(s_giveaway["cancel"]) # Retrieve the giveaway's description. botMsg = await ctx.send(s_giveaway["desc"]) gDescMsg = await self.bot.wait_for('message', check=checkAuth) gDesc = gDescMsg.content await botMsg.delete() await gDescMsg.delete() if gDescMsg.content.lower() == s_giveaway["cancel_word"]: await botMsgCancel.delete() confirmDelMsg = await ctx.send(s_giveaway["canceled"]) await asyncio.sleep(5) await confirmDelMsg.delete() return # Getting the reaction to enter the giveaway. botMsgText = s_giveaway["reaction"] botMsg = await ctx.send(botMsgText) # Waits for the reaction and DONE message. isDone = False while not isDone: msg = await self.bot.wait_for('message', check=checkAuth) if msg.content.lower() == s_giveaway["cancel"]: await botMsgCancel.delete() await botMsg.delete() await msg.delete() confirmDelMsg = await ctx.send(s_giveaway["canceled"]) await asyncio.sleep(5) await confirmDelMsg.delete() return # Checks if the amount of emojis matches the amount of options. # We need to re-cache the message to retrieve the reactions. cacheBotMsg = await ctx.channel.fetch_message(botMsg.id) if len(cacheBotMsg.reactions) != 1: await msg.delete() errorMsg = await ctx.send(s_giveaway["reaction_limit"]) await asyncio.sleep(5) await errorMsg.delete() else: isDone = True reaction = cacheBotMsg.reactions[0] # Asigns reaction. gReac = reaction.emoji # Clears msg. await botMsg.delete() await msg.delete() # Gets the time the giveaway should last. isDone = False while (not isDone): timeAsk = await ctx.send(s_giveaway["time"]) msg = await self.bot.wait_for('message', check=checkAuth) if msg.content.lower() == s_giveaway["cancel_word"]: await botMsgCancel.delete() await msg.delete() await timeAsk.delete() confirmDelMsg = await ctx.send(s_giveaway["canceled"]) await asyncio.sleep(5) await confirmDelMsg.delete() return try: gTimeHour = int(msg.content) isDone = True except: errorMsg = await ctx.send(s_giveaway["time_int_only"]) await asyncio.sleep(2) await errorMsg.delete() isDone = False finally: await timeAsk.delete() await msg.delete() # Confirmation embed. embed = officialEmbed( s_giveaway["confirm_title"], gDesc, footer=s_giveaway["confirm_footer"].format(gTimeHour)) embed.add_field(name=s_giveaway["confirm_reaction"], value=gReac) # Sends embed. botEmbed = await ctx.send(embed=embed) # Asks for validation. botMsg = await ctx.send(s_giveaway["confirm_text"]) giveawayValid = await self.bot.wait_for('message', check=checkAuth) # Checks validation's answer. if not giveawayValid.content.lower() == "yes": cancelMsg = await ctx.send(s_giveaway["canceled"]) # Removes useless msg. await botMsgCancel.delete() await botEmbed.delete() await botMsg.delete() await giveawayValid.delete() await cancelMsg.delete() else: # Removes useless msg. await botMsgCancel.delete() await botMsg.delete() await giveawayValid.delete() # Makes embed. embed = officialEmbed("Giveaway", gDesc) embed.add_field(name=s_giveaway["announce_reaction"], value=gReac) # Sends the giveaway. chan_announcement = self.bot.get_channel(id_announcements) gEmbed = await chan_announcement.send(embed=embed) # Adds the reactions to it. await gEmbed.add_reaction(gReac) # Saves it in the persistence file. endingTime = ( datetime.now() + timedelta(hours=gTimeHour)).strftime('%Y-%m-%dT%H:%M:%S.%f') data = { "desc": gDesc, "ending_time": endingTime, "message_id": gEmbed.id } with open(file_persistence, 'w') as outfile: json.dump(data, outfile) # Waits and fetches results. await self.giveaway_output(data)
async def shibe(self, ctx): response = officialEmbed("Shiba Inu", color=0xff4500) response.set_image( url="https://justsomething.co/wp-content/uploads/2017/12/ryujii-handsome-ridiculously-cute-shiba-japan-758x397.jpg") await ctx.send(embed=response)
async def noot(self,ctx): response = officialEmbed("NOOT NOOT", color=0xffffff) response.set_image(url="https://media1.tenor.com/images/3be64f537ae5dc421d7a8580c1fcde7c/tenor.gif?itemid=15674396") await ctx.send(embed=response)
async def boop(self, ctx, member: discord.Member): desc = "<@{}> was booped by <@{}>!".format(member.id, ctx.author.id) response = officialEmbed("!boop", desc, color=0xFFFFFF) response.set_image(url="http://giphygifs.s3.amazonaws.com/media/99LhY1qc6jG8w/giphy.gif") await ctx.send(embed=response)
async def honk(self, ctx): response = officialEmbed("***HONK HONK HONK***", color=0xff4500) response.set_image( url="https://cdn.discordapp.com/attachments/433685563674198016/630100135623524363/JPEG_20191003_021216.jpg") await ctx.send(embed=response)
async def ashu(self, ctx): response = officialEmbed(title=":slight_smile:", color=0x225999, author="Ashu", author_img="https://i.imgur.com/ojiqdem.png", footer="") await ctx.send(embed=response)