async def welcomer(self, member, settings, goodbye=False): await self.bot.wait_until_ready() channels = [ channel for channel in member.guild.channels if isinstance(channel, discord.TextChannel) ] if goodbye: dict = settings.goodbyes else: dict = settings.welcomes for channel in channels: if str(channel.id) in dict: text = dict[str(channel.id)] if "|" in text: choices = [o for o in text.split("|") if o.strip()] if choices: text = random.choice(choices) text = text.lstrip() text = text.replace('@mention', '<@%s>' % member.id) text = text.replace('@serv', member.guild.name) if 'discord.gg' in member.name.lower(): text = text.replace('@name', '[Removed Invite]') text = text.replace('@name', member.name) text = text.replace('@id', str(member.id)) text = text.replace('@number', str(len(member.guild.members))) text = await self.format_cc(member, channel, text) pic = get_image_from_url(text) if pic: e = discord.Embed() e.set_image(url=pic) text = text.replace(pic, '') try: await channel.send(embed=e, content=text) except discord.Forbidden: try: if goodbye: await channel.send( get_str( "need-embed-permission-for-goodbye", bot=self.bot)) else: await channel.send( get_str( "need-embed-permission-for-welcome", bot=self.bot)) except discord.Forbidden: pass else: try: await channel.send(text) except discord.Forbidden: pass
async def choice(self, ctx, *, name: str): """ {command_prefix}choice [option_1] | [option_2] | [option_3] | ... {command_prefix}choice >>>[command_option_1] | >>>[command_option_2] | [option_3] | ... {help} """ choices = [o for o in name.split("|") if o.strip()] if choices: opt = random.choice(choices) else: return await ctx.send(get_str(ctx, "cmd-choice-empty-option")) opt = opt.strip() opt = await self.bot.format_cc(opt, ctx.message) if "&&" in opt: all = opt.split("&&") if len(all) > 9: return await ctx.send(get_str(ctx, "cmd-choice-too-much-cmds")) for m in all: m = m.lstrip() m = m[3:] ctx.message.content = f"{get_server_prefixes(ctx.bot, ctx.guild)}{m}" await self.bot.process_commands(ctx.message) return if ">>>" in opt: while ">>> " in opt: opt = opt.replace(">>> ", ">>>") opt = ''.join(opt.split(">>>")[1:]) ctx.message.content = f"{get_server_prefixes(ctx.bot, ctx.guild)}{opt}" return await self.bot.process_commands(ctx.message) opt = format_mentions(opt) pic = get_image_from_url(opt) if pic: e = discord.Embed() e.set_image(url=pic) opts = opt.replace(pic, "") try: return await ctx.send(embed=e, content=opts) except discord.Forbidden: return await ctx.send(get_str(ctx, "need-embed-permission")) await ctx.send(opt)
async def meme(self, ctx, pic, *, msg): """ {command_prefix}meme [User] [top_text]|[bottom_text] {command_prefix}meme [custom_url] [top_text]|[bottom_text] {help} """ user = None # msg = unidecode.unidecode(msg) if len(ctx.message.mentions) > (2 if self.bot.user.mention in ctx.prefix else 1): return await ctx.send(get_str(ctx, "cmd-meme-one-user")) if ctx.message.mentions: # mention on a nicknamed user on mobile creates weird issue (no '!' where it should) user = ctx.message.mentions[-1] if str(user.id) not in pic: # It was a prefix user = None if len(ctx.message.mentions) > 1: user = ctx.message.mentions[0] if ctx.guild: if pic.isdigit(): target = ctx.guild.get_member(int(pic)) if target: user = target check_str = [ u for u in ctx.guild.members if u.name.lower() == pic.lower() ] if check_str: user = check_str[0] if user: pic = str(user.avatar_url) pic = pic.strip('<>') msg = " ".join(msg.split()) # remove useless spaces msg = msg.replace('\r', '').replace('\n', '').replace( "-", "--").replace("_", "__").replace("?", "~q").replace( "#", "~h").replace(" ", "_").replace("%", "~p").replace( "/", "~s").replace('"', "''") try: part1 = msg.split("|")[0] except IndexError: part1 = "_" try: part2 = msg.split("|")[1] except IndexError: part2 = "_" if part1 == "": part1 = "_" if part2 == "": part2 = "_" if not get_image_from_url(pic): return await ctx.send( get_str(ctx, "command-invalid-usage").format("{}help meme".format( get_server_prefixes(ctx.bot, ctx.guild)))) if part2 != "_": total = "https://memegen.link/custom/{}/{}.jpg?alt={}".format( part1, part2, pic) else: total = "https://memegen.link/custom/{}/_.jpg?alt={}".format( part1, pic) embed = discord.Embed() embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar_url) # download file async with aiohttp.request("GET", total) as resp: img = BytesIO(await resp.read()) f = discord.File(img, filename="image.png") embed.set_image(url="attachment://image.png") if not user: try: await ctx.message.delete() except discord.HTTPException: pass try: await ctx.send(file=f, embed=embed) except discord.Forbidden: await ctx.send(get_str(ctx, "need-embed-permission"))
async def on_customcommand(self, message, settings, message_content, message_author, cmd_prefix): if settings.customcommands: cmd = message.content.lower()[len(cmd_prefix):].split(" ")[0] rest = None if len(message.content.lower()[len(cmd_prefix):].strip().split( " ")) > 1: rest = ' '.join( message.content[len(cmd_prefix):].split(" ")[1:]) if cmd in settings.customcommands: cmd = await self.format_cc(settings.customcommands[cmd], message) if message.author.id != owner_id and message.author.id in self.config.blacklisted: log.debug( f"[User Blacklisted CustomCommand] {message.author.id}/{message_author} ({message_content})" ) return if ">>>" in cmd: while ">>> " in cmd: cmd = cmd.replace(">>> ", ">>>") if "&&" in cmd: if rest and "&&" in rest: rest = rest.split("&&") all = cmd.split("&&") if len(all) > 9: return await message.channel.send(get_str( message.guild, "cmd-choice-too-much-cmds", self), delete_after=10) for m in all: if m[-3:] == ' ': m = m.lstrip() else: m = m.strip() m = m[3:] if 'download' in m: message.id = 123 # hacky way to say that is a custom command message.content = f"{cmd_prefix}{m}" if len(m.split(' ')) < 2 and rest: message.content += f" {rest}" log.debug( f"[CustomCommandCallMultiple] {message.author.id}/{message_author} ({message.content[:50]})" ) await self.process_commands(message) return else: if 'download' in cmd: message.id = 123 # hacky way to say that is a custom command message.content = cmd[3:] message.content = f"{cmd_prefix}{message.content}" if len(message.content.split(' ')) < 2 and rest: message.content += f" {rest}" log.debug( f"[CustomCommandCall] {message.author.id}/{message_author} ({message.content[:50]})" ) return await self.process_commands(message) pic = get_image_from_url(cmd) if pic: e = discord.Embed() e.set_image(url=pic) cmds = cmd.replace(pic, "") try: await message.channel.send(embed=e, content=cmds) except discord.Forbidden: try: await message.channel.send(get_str( message.guild, "need-embed-permission", self), delete_after=10) except discord.Forbidden: pass else: try: await message.channel.send(cmd) except discord.Forbidden: pass log.debug("[CustomCommand] {}/{} ({})".format( message.author.id, message_author, message_content))