async def on_message(self, message): if message.author == self.bot.user: return for k, v in self.open_rifts.items(): if v.destination == message.channel: msg = "**__{}__**: {}".format(message.author, message.content) msg = escape(msg, mass_mentions=True) await self.bot.send_message(v.source, msg) if v.source == message.channel: msg = "**__{}__**: {}".format(message.author, message.content) msg = escape(msg, mass_mentions=True) await self.bot.send_message(v.destination, msg)
async def on_message(self, message): if message.author == self.bot.user: return for k, v in self.open_rifts.items(): if v.destination == message.channel: msg = "{}: {}".format(message.author, message.content) msg = escape(msg, mass_mentions=True) await self.bot.send_message(v.source, msg)
async def lenny(self, count: int = 1): """(╯°□°)╯︵ ┻━┻""" # max lenny count for easy editing maxcount = 15 if count > maxcount: await self.bot.say( "Cannot post more than {} lennys".format(maxcount)) return # uses lenny.today as a api that returns dicts. # payload etc. given by the community gateway = 'http://lenny.today/api/v1/random?limit={}'.format(count) payload = {} payload['limit'] = 1 headers = {'user-agent': 'Python-Red-cog/1.0'} session = aiohttp.ClientSession() async with session.get(gateway, params=payload, headers=headers) as r: lenny = await r.json() session.close( ) # closes the session to close the connection to the site try: lennylist = [] for x in lenny: # gets the face (lenny) out of dict and puts it in a list lennylist.append("{}\n".format(x['face'])) lenny = "".join(lennylist) # merges the list into a string lenny = escape(lenny, mass_mentions=True, formatting=True) await self.bot.say(lenny) # says the lennys return except: # fail save incase a error does happen return
async def _process_message(self, rift, message, dest): send = message.channel == rift.source destination = rift.destination if send else rift.source me = self.bot.user if destination.is_private else destination.server.me author = message.author sauthor = self.bot.user if destination.is_private else destination.server.get_member(author.id) perms = destination.permissions_for(sauthor) isowner = author.id == self.bot.settings.owner if send and (sauthor is None or not isowner and not perms.send_messages): raise discord.Forbidden(403, "Forbidden") content = message.content embed = None if not isowner or not send: content = "{}: {}".format(author, content) if not isowner and not destination.permissions_for( sauthor).mention_everyone: content = escape(content, mass_mentions=True) if message.attachments and (isowner or destination.permissions_for( sauthor).attach_files): if destination.permissions_for(me).embed_links: attach = message.attachments[0] embed = discord.Embed(description="{}\n**[{}]({})**".format( xbytes(attach["size"]), attach["filename"], attach["url"]), colour=randint(0, 0xFFFFFF)) embed.set_image(url=message.attachments[0]["url"]) if len(message.attachments) > 1: rest = message.attachments[1:] embed.set_footer(" | ".join("**[{}]({})** ({})".format( a["filename"], a["url"], xbytes(a["size"])) for a in rest)) else: content += "\n\n" + "\n".join("{} ({})".format(a["url"], xbytes(a["size"])) for a in message.attachments) if isinstance(dest, discord.Message): return await self.bot.edit_message(dest, content, embed=embed) else: return await self.bot.send_message(dest, content, embed=embed)