async def phonebook(self, ctx, *, look_up=None): """Lets you page through the phonebook - or optionally lets you search for a server name or number.""" # Build our phone list entries = [] for guild in self.bot.guilds: teleNum = self.settings.getServerStat(guild, "TeleNumber") if teleNum: entries.append({ "name": guild.name, "value": teleNum[:3] + "-" + teleNum[3:] }) if not len(entries): await ctx.send(":telephone: The phonebook is *empty!*") return # Sort alphabetically entries = sorted(entries, key=lambda x: x["name"]) if look_up == None: await PickList.PagePicker(title=":telephone: Phonebook", list=entries, ctx=ctx).pick() return # Search time! look_up_num = re.sub(r'\W+', '', look_up) id_ratio = 0 if len(look_up_num): look_up_num = look_up_num if len( look_up_num) < 7 else look_up_num[:3] + "-" + look_up_num[3:] idMatch = FuzzySearch.search(look_up_num, entries, 'value', 3) id_ratio = idMatch[0]['Ratio'] if id_ratio == 1: # Found it! return await Message.Embed(title=":telephone: Phonebook", fields=[idMatch[0]["Item"]], color=ctx.author).send(ctx) # Look up by name now nameMatch = FuzzySearch.search(look_up, entries, 'name', 3) if nameMatch[0]['Ratio'] == 1: # Exact name # Found it! return await Message.Embed(title=":telephone: Phonebook", fields=[nameMatch[0]["Item"]], color=ctx.author).send(ctx) # now we need to find which is better matchCheck = [] if nameMatch[0]['Ratio'] > id_ratio: matchCheck = nameMatch else: matchCheck = idMatch fields = [m["Item"] for m in matchCheck] return await Message.Embed( title=":telephone: Phonebook - Closest Matches", fields=fields, color=ctx.author).send(ctx)
async def help(self, ctx, *, command = None): """Lists the bot's commands and cogs. You can pass a command or cog to this to get more info (case-sensitive).""" result = await self._get_info(ctx, command) if result == None: # Get a list of all commands and modules and server up the 3 closest cog_name_list = [] com_name_list = [] for cog in self.bot.cogs: if not cog in cog_name_list: if not len(self.bot.get_cog(cog).get_commands()): # Skip empty cogs continue cog_commands = self.bot.get_cog(cog).get_commands() hid = True for comm in cog_commands: if comm.hidden: continue hid = False if not comm.name in com_name_list: com_name_list.append(comm.name) if not hid: cog_name_list.append(cog) # Get cog list: cog_match = FuzzySearch.search(command, cog_name_list) com_match = FuzzySearch.search(command, com_name_list) # Build the embed m = Message.Embed(force_pm=True,pm_after=25) if type(ctx.author) is discord.Member: m.color = ctx.author.color m.title = "No command called \"{}\" found".format(command) if len(cog_match): cog_mess = "" for pot in cog_match: cog_mess += '└─ {}\n'.format(pot['Item'].replace('`', '\\`')) m.add_field(name="Close Cog Matches:", value=cog_mess) if len(com_match): com_mess = "" for pot in com_match: com_mess += '└─ {}\n'.format(pot['Item'].replace('`', '\\`')) m.add_field(name="Close Command Matches:", value=com_mess) m.footer = { "text" : "Remember that commands and cogs are case-sensitive.", "icon_url" : self.bot.user.avatar_url } await m.send(ctx) return m = Message.Embed(**result) m.force_pm = True m.pm_after = 25 # Build the embed if type(ctx.author) is discord.Member: m.color = ctx.author.color m.footer = self.bot.description + " - Type \"{}help command\" for more info on a command. \n".format(self._get_prefix(ctx)) await m.send(ctx)
async def meme(self, ctx, template_id=None, text_zero=None, text_one=None): """Generate Memes! You can get a list of meme templates with the memetemps command. If any fields have spaces, they must be enclosed in quotes.""" if not self.canDisplay(ctx.message.guild): return if text_one == None: # Set as space if not included text_one = " " if template_id == None or text_zero == None or text_one == None: msg = "Usage: `{}meme [template_id] [text#1] [text#2]`\n\n Meme Templates can be found using `$memetemps`".format( ctx.prefix) await ctx.channel.send(msg) return templates = await self.getTemps() chosenTemp = None msg = '' idMatch = FuzzySearch.search(template_id, templates, 'id', 1) if idMatch[0]['Ratio'] == 1: # Perfect match chosenTemp = idMatch[0]['Item']['id'] else: # Imperfect match - assume the name nameMatch = FuzzySearch.search(template_id, templates, 'name', 1) chosenTemp = nameMatch[0]['Item']['id'] if nameMatch[0]['Ratio'] < 1: # Less than perfect, still msg = 'I\'ll assume you meant *{}*.'.format( nameMatch[0]['Item']['name']) url = "https://api.imgflip.com/caption_image" username = self.settings.getServerStat(ctx.message.guild, "ImgflipUsername") password = self.settings.getServerStat(ctx.message.guild, "ImgflipPassword") payload = { 'template_id': chosenTemp, 'username': username, 'password': password, 'text0': text_zero, 'text1': text_one } result_json = await DL.async_post_json(url, payload) # json.loads(r.text) result = result_json["data"]["url"] if msg: # result = '{}\n{}'.format(msg, result) await ctx.channel.send(msg) # Download Image - set title as a space so it disappears on upload await Message.Embed(image=result, color=ctx.author).send(ctx)
async def meme(self, ctx, template_id=None, text_zero=None, text_one=None): """Generate Meme""" if not self.canDisplay(ctx.message.server): return if text_one == None: # Set as space if not included text_one = " " if template_id == None or text_zero == None or text_one == None: msg = "Usage: `{}meme [template_id] [text#1] [text#2]`\n\n Meme Templates can be found using `$memetemps`".format( ctx.prefix) await self.bot.send_message(ctx.message.channel, msg) return templates = self.getTemps() chosenTemp = None msg = '' idMatch = FuzzySearch.search(template_id, templates, 'id', 1) if idMatch[0]['Ratio'] < 1: # Not a perfect match - try name nameMatch = FuzzySearch.search(template_id, templates, 'name', 1) if nameMatch[0]['Ratio'] > idMatch[0]['Ratio']: # Better match on name than id chosenTemp = nameMatch[0]['Item']['id'] if not nameMatch[0]['Ratio'] == 1: # Still not a perfect match... msg = 'I\'ll assume you meant *{}*.'.format( nameMatch[0]['Item']['name']) else: # ID is a perfect match chosenTemp = idMatch[0]['Item']['id'] url = "https://api.imgflip.com/caption_image" payload = { 'template_id': chosenTemp, 'username': '******', 'password': '******', 'text0': text_zero, 'text1': text_one } r = requests.post(url, data=payload) result_json = json.loads(r.text) result = result_json["data"]["url"] if msg: # result = '{}\n{}'.format(msg, result) await self.bot.send_message(ctx.message.channel, msg) # Download Image - set title as a space so it disappears on upload await GetImage.get(result, self.bot, ctx.message.channel, " ")
async def meme(self, ctx, template_id=None, text_zero=None, text_one=None): """Generate Memes! You can get a list of meme templates with the memetemps command. If any fields have spaces, they must be enclosed in quotes.""" if not self.canDisplay(ctx.message.guild): return if text_one == None: # Set as space if not included text_one = " " if any((x == None for x in (template_id, text_zero, text_one))): msg = "Usage: `{}meme [template_id] [text#1] [text#2]`\n\n Meme Templates can be found using `$memetemps`".format( ctx.prefix) return await ctx.send(msg) templates = await self.getTemps() chosenTemp = gotName = None idMatch = FuzzySearch.search(template_id, templates, 'id', 1) if idMatch[0]['Ratio'] == 1: # Perfect match chosenTemp = idMatch[0]['Item']['id'] gotName = idMatch[0]['Item']['name'] else: # Imperfect match - assume the name nameMatch = FuzzySearch.search(template_id, templates, 'name', 1) chosenTemp = nameMatch[0]['Item']['id'] gotName = nameMatch[0]['Item']['name'] url = "https://api.imgflip.com/caption_image" payload = { 'template_id': chosenTemp, 'username': '******', 'password': '******', 'text0': text_zero, 'text1': text_one } result_json = await DL.async_post_json(url, payload) result = result_json["data"]["url"] await Message.Embed( url=result, title=text_zero + " - " + text_one if text_one != " " else text_zero, image=result, color=ctx.author, footer='Powered by imgflip.com - using template id {}: {}'.format( chosenTemp, gotName)).send(ctx)
async def settz(self, ctx, *, tz: str = None): """Sets your TimeZone - Overrides your UTC offset - and accounts for DST.""" usage = 'Usage: `{}settz [Region/City]`\nYou can get a list of available TimeZones with `{}listtz`'.format( ctx.prefix, ctx.prefix) if not tz: self.settings.setGlobalUserStat(ctx.author, "TimeZone", None) await ctx.channel.send( "*{}*, your TimeZone has been removed!".format( DisplayName.name(ctx.author))) return not_found = 'TimeZone `{}` not found!'.format(tz.replace('`', '\\`')) # Let's get the timezone list tz_list = FuzzySearch.search(tz, pytz.all_timezones, None, 3) if not tz_list[0]['Ratio'] == 1: # Setup and display the picker msg = not_found + '\nSelect one of the following close matches:' index, message = await PickList.Picker( title=msg, list=[x["Item"] for x in tz_list], ctx=ctx).pick() # Check if we errored/cancelled if index < 0: await message.edit(content=not_found) return # We got a time zone self.settings.setGlobalUserStat(ctx.author, "TimeZone", tz_list[index]['Item']) await message.edit( content="TimeZone set to `{}`!".format(tz_list[index]['Item'])) return # We got a time zone self.settings.setGlobalUserStat(ctx.author, "TimeZone", tz_list[0]['Item']) msg = "TimeZone set to `{}`!".format(tz_list[0]['Item']) message = await ctx.send(msg)
async def settz(self, ctx, *, tz: str = None): """Sets your TimeZone - Overrides your UTC offset - and accounts for DST.""" usage = 'Usage: `{}settz [Region/City]`\nYou can get a list of available TimeZones with `{}listtz`'.format( ctx.prefix, ctx.prefix) if not tz: self.settings.setGlobalUserStat(ctx.author, "TimeZone", None) await ctx.channel.send( "*{}*, your TimeZone has been removed!".format( DisplayName.name(ctx.author))) return # Let's get the timezone list tz_list = FuzzySearch.search(tz, pytz.all_timezones, None, 3) if not tz_list[0]['Ratio'] == 1: # We didn't find a complete match msg = "I couldn't find that TimeZone!\n\nMaybe you meant one of the following?\n```" for tz in tz_list: msg += tz['Item'] + "\n" msg += '```' await ctx.channel.send(msg) return # We got a time zone self.settings.setGlobalUserStat(ctx.author, "TimeZone", tz_list[0]['Item']) await ctx.channel.send("TimeZone set to *{}!*".format( tz_list[0]['Item']))
def getTimeFromTZ(self, tz, t = None): # Assume sanitized zones - as they're pulled from pytz # Let's get the timezone list tz_list = FuzzySearch.search(tz, pytz.all_timezones, None, 3) if not tz_list[0]['Ratio'] == 1: # We didn't find a complete match return None zone = pytz.timezone(tz_list[0]['Item']) if t == None: zone_now = datetime.datetime.now(zone) else: zone_now = t.astimezone(zone) return { "zone" : tz_list[0]['Item'], "time" : zone_now.strftime("%I:%M %p") }
async def listtz(self, ctx, *, tz_search=None): """List all the supported TimeZones in PM.""" if not tz_search: msg = "__Available TimeZones:__\n\n" for tz in pytz.all_timezones: msg += tz + "\n" else: tz_list = FuzzySearch.search(tz_search, pytz.all_timezones) msg = "__Top 3 TimeZone Matches:__\n\n" for tz in tz_list: msg += tz['Item'] + "\n" await Message.say(self.bot, msg, ctx.channel, ctx.author, 1)
async def link(self, ctx, *, name: str = None): """Retrieve a link from the link list.""" channel = ctx.message.channel author = ctx.message.author server = ctx.message.guild # Check if we're suppressing @here and @everyone mentions if self.settings.getServerStat(ctx.message.guild, "SuppressMentions").lower() == "yes": suppress = True else: suppress = False if not name: msg = 'Usage: `{}link "[link name]"`'.format(ctx.prefix) await channel.send(msg) return linkList = self.settings.getServerStat(server, "Links") if not linkList or linkList == []: msg = 'No links in list! You can add some with the `{}addlink "[link name]" [url]` command!'.format( ctx.prefix) await channel.send(msg) return for alink in linkList: if alink['Name'].lower() == name.lower(): msg = '**{}:**\n{}'.format(alink['Name'], alink['URL']) # Check for suppress if suppress: msg = Nullify.clean(msg) await channel.send(msg) return msg = 'Link "*{}*" not found!'.format(name) # No link - let's fuzzy search potentialList = FuzzySearch.search(name, linkList, 'Name') if len(potentialList): msg += '\n\nDid you maybe mean one of the following?\n```\n' for pot in potentialList: msg += '{}\n'.format(pot['Item']['Name']) msg += '```' # Check for suppress if suppress: msg = Nullify.clean(msg) await channel.send(msg)
async def listtz(self, ctx, *, tz_search = None): """List all the supported TimeZones in PM.""" msg = "" if not tz_search: title = "Available TimeZones" for tz in pytz.all_timezones: msg += tz + "\n" else: tz_list = FuzzySearch.search(tz_search, pytz.all_timezones) title = "Top 3 TimeZone Matches" for tz in tz_list: msg += tz['Item'] + "\n" await Message.EmbedText(title=title, color=ctx.author, description=msg).send(ctx)
async def setpersonality(self, ctx, *, name=None): """Sets the bots personality (owner only). List available here: http://pandorabots.com/botmaster/en/mostactive""" channel = ctx.message.channel author = ctx.message.author server = ctx.message.server # Only allow owner to change server stats serverDict = self.settings.serverDict try: owner = serverDict['Owner'] except KeyError: owner = None if owner == None: # No owner set msg = 'I have not been claimed, *yet*.' await self.bot.send_message(channel, msg) return else: if not author.id == owner: msg = 'You are not the *true* owner of me. Only the rightful owner can change my personality.' await self.bot.send_message(channel, msg) return # Update bot list await self._getBots() if name == None: await self.bot.send_message( ctx.message.channel, 'You need to specify a bot name. List here: http://pandorabots.com/botmaster/en/mostactive' ) return # Fuzzy match nameMatch = FuzzySearch.search(name, self.botList, 'Name', 1) self.botID = nameMatch[0]['Item']['ID'] self.botName = nameMatch[0]['Item']['Name'] if nameMatch[0]['Ratio'] < 1: # Not a perfect match - state assumption msg = "I'll assume you meant *{}.* Personality set!".format( nameMatch[0]['Item']['Name']) else: # Perfect match msg = "Personality set to *{}!*".format( nameMatch[0]['Item']['Name']) await self.bot.send_message(ctx.message.channel, msg)
async def listtz(self, ctx, *, tz_search=None): """Mengirimkan list TimeZone yang tersedia ke Private Message mu.""" confirm = ['ya'] msgConfirm = "Command ini akan mengirimkan 5 halaman embed kedalam pesan DM mu.\nKetik `ya` untuk melanjutkan" em = discord.Embed(color=0XFF8C00, description=msgConfirm) em.set_footer(text="{}#{}".format(ctx.author.name, ctx.author.discriminator), icon_url="{}".format(ctx.author.avatar_url)) Msg = await ctx.send(embed=em) try: msg = await self.bot.wait_for( 'message', timeout=15, check=lambda msg: msg.author == ctx.author) except: await Msg.delete() msgConfirm = 'Waktu habis, command mu telah dibatalkan' em = discord.Embed(color=0XFF8C00, description=msgConfirm) em.set_footer(text="{}#{}".format(ctx.author.name, ctx.author.discriminator), icon_url="{}".format(ctx.author.avatar_url)) return await ctx.send(embed=em, delete_after=10) message = str(msg.content.lower()) if message not in confirm and message not in ['ya']: await Msg.delete() msgConfirm = 'Command dibatalkan.\nKamu memasukan konfirmasi yang salah' em = discord.Embed(color=0XFF8C00, description=msgConfirm) em.set_footer(text="{}#{}".format(ctx.author.name, ctx.author.discriminator), icon_url="{}".format(ctx.author.avatar_url)) return await ctx.send(embed=em, delete_after=10) msg = "" if not tz_search: title = "TimeZones Tersedia" for tz in pytz.all_timezones: msg += tz + "\n" else: tz_list = FuzzySearch.search(tz_search, pytz.all_timezones) title = "Top 3 TimeZone yang cocok" for tz in tz_list: msg += tz['Item'] + "\n" await Msg.delete() await Message.EmbedText(title=title, color=ctx.author, description=msg).send(ctx)
def getTimeFromTZ(tz, t=None, strft="%Y-%m-%d %I:%M %p", clock=True): # Assume sanitized zones - as they're pulled from pytz # Let's get the timezone list tz_list = FuzzySearch.search(tz, pytz.all_timezones, None, 3) if not tz_list[0]['Ratio'] == 1: # We didn't find a complete match return None zone = pytz.timezone(tz_list[0]['Item']) if t == None: zone_now = datetime.datetime.now(zone) else: zone_now = pytz.utc.localize(t, is_dst=None).astimezone(zone) #zone_now = t.astimezone(zone) if clock: ti = getClockForTime(zone_now.strftime(strft)) else: ti = zone_now.strftime(strft) return {"zone": tz_list[0]['Item'], "time": ti}
async def rawtag(self, ctx, *, name : str = None): """Retrieve a tag's raw markdown from the tag list.""" channel = ctx.message.channel author = ctx.message.author server = ctx.message.guild # Check if we're suppressing @here and @everyone mentions if self.settings.getServerStat(ctx.message.guild, "SuppressMentions"): suppress = True else: suppress = False if not name: msg = 'Usage: `{}rawtag "[tag name]"`'.format(ctx.prefix) await channel.send(msg) return tagList = self.settings.getServerStat(server, "Tags") if not tagList or tagList == []: msg = 'No tags in list! You can add some with the `{}addtag "[tag name]" [tag]` command!'.format(ctx.prefix) await channel.send(msg) return for atag in tagList: if atag['Name'].lower() == name.lower(): msg = '**{}:**\n{}'.format(atag['Name'], atag['URL'].replace('\\', '\\\\').replace('*', '\\*').replace('`', '\\`').replace('_', '\\_')) # Check for suppress if suppress: msg = Nullify.clean(msg) await channel.send(msg) return not_found = 'Tag `{}` not found!'.format(name.replace('`', '\\`')) # No tag - let's fuzzy search potentialList = FuzzySearch.search(name, tagList, 'Name') if len(potentialList): # Setup and display the picker msg = not_found + '\n\nSelect one of the following close matches:' index, message = await PickList.Picker( title=msg, list=[x["Item"]["Name"] for x in potentialList], ctx=ctx ).pick() # Check if we errored/cancelled if index < 0: await message.edit(content=not_found) return # Display the tag for atag in tagList: if atag["Name"] == potentialList[index]["Item"]["Name"]: msg = '**{}:**\n{}'.format(atag['Name'], atag['URL'].replace('\\', '\\\\').replace('*', '\\*').replace('`', '\\`').replace('_', '\\_')) # Check for suppress if suppress: msg = Nullify.clean(msg) await message.edit(content=msg) return await message.edit(content="Tag `{}` no longer exists!".format( potentialList[index]["Item"]["Name"].replace('`', '\\`')) ) return # Here we have no potentials await ctx.send(not_found) return
async def tag(self, ctx, *, name : str = None): """Retrieve a tag from the tag list.""" # Try to invoke another command # await ctx.invoke(self.alt_lists[1]["command"], name=name) # return our_list = "Tags" channel = ctx.message.channel author = ctx.message.author server = ctx.message.guild # Check if we're suppressing @here and @everyone mentions if self.settings.getServerStat(ctx.message.guild, "SuppressMentions"): suppress = True else: suppress = False if not name: msg = 'Usage: `{}tag "[tag name]"`'.format(ctx.prefix) await channel.send(msg) return tagList = self.settings.getServerStat(server, our_list) not_found = 'Tag `{}` not found!'.format(name.replace('`', '\\`')) # Check others other_commands = [] other_names = [] for i in self.alt_lists: if i["list"] == our_list: # Our list - skip continue check_list = self.settings.getServerStat(server, i["list"]) if any(x["Name"].lower() == name.lower() for x in check_list): # Add the list other_commands.append(i) other_names.append(ctx.prefix + i["command"] + " " + name.replace('`', '')) if not tagList or tagList == []: no_tags = 'No tags in list! You can add some with the `{}addtag "[tag name]" [tag]` command!'.format(ctx.prefix) if not len(other_commands): # No other matches await ctx.send(no_tags) return msg = no_tags + "\n\nMaybe you meant:" index, message = await PickList.Picker( title=msg, list=other_names, ctx=ctx ).pick() # Check if we errored/cancelled if index < 0: await message.edit(content=no_tags) return # Got something await message.edit(content="`{}`".format(other_names[index])) # Invoke await ctx.invoke(self.bot.all_commands.get(other_commands[index]["command"]), name=name) return for atag in tagList: if atag['Name'].lower() == name.lower(): msg = '**{}:**\n{}'.format(atag['Name'], atag['URL']) # Check for suppress if suppress: msg = Nullify.clean(msg) await channel.send(msg) return # No tag - let's fuzzy search potentialList = FuzzySearch.search(name, tagList, 'Name') if len(potentialList): # Setup and display the picker msg = not_found + '\n\nSelect one of the following close matches:' p_list = [x["Item"]["Name"] for x in potentialList] p_list.extend(other_names) index, message = await PickList.Picker( title=msg, list=p_list, ctx=ctx ).pick() # Check if we errored/cancelled if index < 0: await message.edit(content=not_found) return # Check if we have another command if index >= len(potentialList): # We're into our other list await message.edit(content="`{}`".format(other_names[index - len(potentialList)])) # Invoke await ctx.invoke(self.bot.all_commands.get(other_commands[index - len(potentialList)]["command"]), name=name) return # Display the tag for atag in tagList: if atag["Name"] == potentialList[index]["Item"]["Name"]: msg = '**{}:**\n{}'.format(atag['Name'], atag['URL']) # Check for suppress if suppress: msg = Nullify.clean(msg) await message.edit(content=msg) return await message.edit(content="Tag `{}` no longer exists!".format( potentialList[index]["Item"]["Name"].replace('`', '\\`')) ) return # Here we have no potentials await ctx.send(not_found) return
async def meme(self, ctx, template_id=None, text_zero=None, text_one=None): """Meme generator! Kamu dapat melihat list template meme dengan command `acx!memetemps`. jika kalimat/template dipisahkan dengan spasi, harus menggunakan tanda kutip (\"). Contoh: • acx!meme [template/id meme] [text1] [text2] • acx!meme 163573 \"BACOT\" • acx!meme \"Imagination Spongebob\" \"BACOT\"""" if not self.canDisplay(ctx.message.guild): return if text_one == None: # Set as space if not included text_one = " " if template_id == None or text_zero == None or text_one == None: msg = "> **Panduan penggunaan**\n" msg += "> `{}meme [template/id meme] [text#1] [text#2]`\n".format( ctx.prefix) msg += "> **Contoh**\n" msg += "> • `{}meme 163573 \"BACOT\"`\n".format(ctx.prefix) msg += "> • `{}meme \"Imagination Spongebob\" \"BACOT\" \"LOE!\"`\n> \n".format( ctx.prefix) msg += "> list meme bisa dilihat disini\n" msg += "> `{}memetemps`".format(ctx.prefix) em = discord.Embed(color=0XFF8C00, description=msg) em.set_author( name="Meme maker", url="https://acinonyxesports.com", icon_url= "https://cdn.discordapp.com/attachments/518118753226063887/725569194304733435/photo.jpg" ) em.set_footer(text="Request by : {}".format(ctx.author.name), icon_url="{}".format(ctx.author.avatar_url)) await ctx.channel.send(embed=em) return templates = await self.getTemps() chosenTemp = None msg = '' idMatch = FuzzySearch.search(template_id, templates, 'id', 1) if idMatch[0]['Ratio'] == 1: # Perfect match chosenTemp = idMatch[0]['Item']['id'] else: # Imperfect match - assume the name nameMatch = FuzzySearch.search(template_id, templates, 'name', 1) chosenTemp = nameMatch[0]['Item']['id'] if nameMatch[0]['Ratio'] < 1: # Less than perfect, still msg = 'Mungkin yang kamu maksud *{}*.'.format( nameMatch[0]['Item']['name']) url = "https://api.imgflip.com/caption_image" payload = { 'template_id': chosenTemp, 'username': '******', 'password': '******', 'text0': text_zero, 'text1': text_one } result_json = await DL.async_post_json(url, payload) # json.loads(r.text) result = result_json["data"]["url"] if msg: # result = '{}\n{}'.format(msg, result) await ctx.channel.send(msg) # Download Image - set title as a space so it disappears on upload await Message.Embed(image=result, color=ctx.author).send(ctx)
async def phonebook(self, ctx, *, look_up=None): """Displays up to 20 entries in the phone book - or optionally lets you search for a server name or number.""" # Build our phone list entries = [] for guild in self.bot.guilds: teleNum = self.settings.getServerStat(guild, "TeleNumber") if teleNum: entries.append({"Name": guild.name, "Number": teleNum}) if not len(entries): await ctx.send(":telephone: The phonebook is *empty!*") return max_entries = 20 if look_up == None: if len(entries) > 20: title = ":telephone: __First 20 of {} Phonebook Entries:__\n\n".format( len(entries)) else: max_entries = len(entries) title = ":telephone: __Phonebook:__\n\n" count = 0 for i in entries: count += 1 num = i['Number'] i_form = num[:3] + "-" + num[3:] title += "{}. {} - *{}*\n".format(count, i["Name"], i_form) await ctx.send(self.suppressed(ctx.guild, title)) return # Search time! look_up_num = re.sub(r'\W+', '', look_up) id_ratio = 0 if len(look_up_num): idMatch = FuzzySearch.search(look_up_num, entries, 'Number', 3) id_ratio = idMatch[0]['Ratio'] if id_ratio == 1: # Found it! num = idMatch[0]['Item']['Number'] i_form = num[:3] + "-" + num[3:] msg = ":telephone: __Phonebook:__\n\n{} - *{}*".format( idMatch[0]['Item']['Name'], i_form) await ctx.send(self.suppressed(ctx.guild, msg)) return # Look up by name now nameMatch = FuzzySearch.search(look_up, entries, 'Name', 3) if nameMatch[0]['Ratio'] == 1: # Exact name # Found it! num = nameMatch[0]['Item']['Number'] i_form = num[:3] + "-" + num[3:] msg = ":telephone: __Phonebook:__\n\n{} - *{}*".format( nameMatch[0]['Item']['Name'], i_form) await ctx.send(self.suppressed(ctx.guild, msg)) return # now we need to find which is better matchCheck = [] if nameMatch[0]['Ratio'] > id_ratio: matchCheck = nameMatch else: matchCheck = idMatch msg = ":telephone: __Phonebook - Closest Matches:__\n\n" count = 0 for m in matchCheck: count += 1 num = m['Item']['Number'] i_form = num[:3] + "-" + num[3:] msg += "{}. {} - *{}*\n".format(count, m['Item']['Name'], i_form) await ctx.send(self.suppressed(ctx.guild, msg))
async def settz(self, ctx, *, tz: str = None): """Mengatur TimeZone milik mu, dan timestamp UTC bot akan otomatis mengikuti local TimeZone yang kamu setting. Contoh: `acx settz Asia/Jakarta` Kamu juga dapat melihat list TimeZone dengan `acx listtz` """ em = discord.Embed( color=0XFF8C00, description= "> Mengatur TimeZone milik mu, dan timestamp UTC bot akan otomatis mengikuti TimeZone yang kamu setting\n> \n" "> **Panduan**\n" "> `{}settz [Wilayah/Kota]`\n> \n" "> Kamu juga dapat melihat list TimeZone dengan `{}listtz`".format( ctx.prefix, ctx.prefix)) em.set_thumbnail(url="{}".format(ctx.message.guild.icon_url)) em.set_footer( text="Saat mengetik command, tanda [] tidak usah digunakan\n{}". format(ctx.author), icon_url="{}".format(ctx.author.avatar_url)) if not tz: self.settings.setGlobalUserStat(ctx.author, "TimeZone", None) msg = "*{}*, TimeZone kamu telah dihapus!".format( DisplayName.name(ctx.author)) em = discord.Embed(color=0XFF8C00, description=msg) em.set_footer(text="{}".format(ctx.author), icon_url="{}".format(ctx.author.avatar_url)) await ctx.channel.send(embed=em) return not_found = 'TimeZone `{}` Tidak ditemukan!'.format( tz.replace('`', '\\`')) # Let's get the timezone list tz_list = FuzzySearch.search(tz, pytz.all_timezones, None, 3) if not tz_list[0]['Ratio'] == 1: # Setup and display the picker msg = not_found + '\nMungkin TimeZone dibawah ini yang kamu maksud:' index, message = await PickList.Picker( title=msg, list=[x["Item"] for x in tz_list], ctx=ctx).pick() # Check if we errored/cancelled if index < 0: em = discord.Embed(color=0XFF8C00, description=not_found) em.set_footer(text="{}".format(ctx.author), icon_url="{}".format(ctx.author.avatar_url)) await message.edit(embed=em) return # We got a time zone self.settings.setGlobalUserStat(ctx.author, "TimeZone", tz_list[index]['Item']) msgDone = "TimeZone telah di setting ke `{}`!".format( tz_list[index]['Item']) em = discord.Embed(color=0XFF8C00, description=msgDone) em.set_footer(text="{}".format(ctx.author), icon_url="{}".format(ctx.author.avatar_url)) await message.delete() await ctx.send(embed=em) return # We got a time zone self.settings.setGlobalUserStat(ctx.author, "TimeZone", tz_list[0]['Item']) msgDone = "TimeZone telah di setting ke `{}`!".format( tz_list[0]['Item']) em = discord.Embed(color=0XFF8C00, description=msgDone) em.set_footer(text="{}".format(ctx.author), icon_url="{}".format(ctx.author.avatar_url)) message = await ctx.send(embed=em)
async def _get_item(self, ctx, name, l_role="RequiredLinkRole", l_list="Links", l_name="Link", l_key="URL", raw=False): # Helper function to pull items from lists if not name: em = discord.Embed(color=0XFF8C00, description='**Panduan**\n' '`{}{}[[name]] "[[[name]] name]"`'.format( ctx.prefix, "raw" if raw else "").replace( "[[name]]", l_name.lower())) em.set_footer(text="{}#{}".format(ctx.author.name, ctx.author.discriminator), icon_url="{}".format(ctx.author.avatar_url)) return await ctx.send(embed=em) itemList = self.settings.getServerStat(ctx.guild, l_list) # Check other lists other_commands = [] other_names = [] for i in self.alt_lists: if i["list"] == l_list: # Our list - skip continue check_list = self.settings.getServerStat(ctx.guild, i["list"]) if any(x["Name"].lower() == name.lower() for x in check_list): # Add the list other_commands.append(i) other_names.append( Utils.suppressed( ctx, "{}{} {}".format(ctx.prefix, i["command"], name))) if not itemList or itemList == []: no_items = 'No [[name]]s in list! You can add some with the `{}add[[name]] "[[[name]] name]" [[[key]]]` command!'.format( ctx.prefix).replace("[[name]]", l_name.lower()).replace( "[[key]]", l_key.lower()) if raw or not len(other_commands): # No other matches return await ctx.send(no_items) msg = no_items + "\n\nMaybe you meant:" index, message = await PickList.Picker(title=msg, list=other_names, ctx=ctx).pick() # Check if we errored/cancelled if index < 0: return await message.edit(content=no_items) # Got something await message.edit(content="`{}`".format(other_names[index])) # Invoke return await ctx.invoke(self.bot.all_commands.get( other_commands[index]["command"]), name=name) for item in itemList: if item['Name'].lower() == name.lower(): msg = '**{}:**\n{}'.format( item['Name'], discord.utils.escape_markdown(item[l_key]) if raw else item[l_key]) return await ctx.send(Utils.suppressed(ctx, msg)) not_found = Utils.suppressed( ctx, '`{}` not found in {} list!'.format( name.replace("`", "").replace("\\", ""), l_name.lower())) # No matches - let's fuzzy search potentialList = FuzzySearch.search(name, itemList, 'Name') if len(potentialList): # Setup and display the picker msg = not_found + '\n\nSelect one of the following close matches:' p_list = [x["Item"]["Name"] for x in potentialList] p_list.extend(other_names) index, message = await PickList.Picker(title=msg, list=p_list, ctx=ctx).pick() # Check if we errored/cancelled if index < 0: return await message.edit(content=not_found) # Check if we have another command if index >= len(potentialList): # We're into our other list await message.edit( content="`{}`".format(other_names[index - len(potentialList)])) # Invoke return await ctx.invoke(self.bot.all_commands.get( other_commands[index - len(potentialList)]["command"]), name=name) # Display the item for item in itemList: if item["Name"] == potentialList[index]["Item"]["Name"]: msg = '**{}:**\n{}'.format( item['Name'], discord.utils.escape_markdown(item[l_key]) if raw else item[l_key]) return await message.edit( content=Utils.suppressed(ctx, msg)) return await message.edit( content="{} `{}` no longer exists!".format( l_name, potentialList[index]["Item"]["Name"].replace( "`", "").replace("\\", ""))) # Here we have no potentials return await ctx.send(not_found)
async def help(self, ctx, *, command=None): """Melihat list help. You can pass a command or cog to this to get more info (case-sensitive).""" result = await self._get_info(ctx, command) if result == None: # Get a list of all commands and modules and server up the 3 closest cog_name_list = [] com_name_list = [] for cog in self.bot.cogs: if not cog in cog_name_list: if not len(self.bot.get_cog(cog).get_commands()): # Skip empty cogs continue cog_commands = self.bot.get_cog(cog).get_commands() hid = True for comm in cog_commands: if comm.hidden: continue hid = False if not comm.name in com_name_list: com_name_list.append(comm.name) if not hid: cog_name_list.append(cog) # Get cog list: cog_match = FuzzySearch.search(command, cog_name_list) com_match = FuzzySearch.search(command, com_name_list) # Build the embed m = Message.Embed(force_pm=True, pm_after=25) if type(ctx.author) is discord.Member: m.color = 0XFF8C00 m.title = "Tidak ada command \"{}\" yang ditemukan".format( Nullify.clean(command)) if len(cog_match): cog_mess = "" for pot in cog_match: cog_mess += '└─ {}\n'.format(pot['Item'].replace( '`', '\\`')) m.add_field(name="Mungkin Kategori ini yang kamu maksud:", value=cog_mess) if len(com_match): com_mess = "" for pot in com_match: com_mess += '└─ {}\n'.format(pot['Item'].replace( '`', '\\`')) m.add_field(name="Mungkin Command ini yang kamu maksud:", value=com_mess) m.footer = { "text": "Ingat Kategori dan command peka terhadap huruf BESAR/kecil.", "icon_url": self.bot.user.avatar_url } await m.send(ctx) return m = Message.Embed(**result) m.force_pm = True m.pm_after = 25 # Build the embed if type(ctx.author) is discord.Member: m.color = 0XFF8C00 m.footer = self.bot.description + "\nKetik \"{}help command\" untuk informasi lebih lanjut. \n".format( self._get_prefix(ctx)) await m.send(ctx)