import discord from discord.ext import commands import random import os from datetime import datetime import requests import wikia import base64 import aiohttp import runescapeapi class bots_commands: def __init__(self, bot: commands.Bot): self.bot = bot self.picked_wikis = {} @commands.command(pass_context=True) async def ping(self, ctx): """bot replys with pong""" now = ctx.message.timestamp msg = await self.bot.say("Pong! ๐Ÿ“") msg_timestamp = msg.timestamp sub = msg_timestamp - now await self.bot.edit_message(msg, new_content="Pong! ๐Ÿ“ **took {}ms**" .format(sub.total_seconds()*1000)) @commands.command(pass_context=True) async def say(self, ctx, *, something): """bot echos what you say then deletes your message""" await self.bot.say(f"**{ctx.message.author} said:** {something}") await self.bot.delete_message(ctx.message) @commands.command(pass_context=True) async def am_i_cool(self, ctx): """decides whether ur cool or not""" mention = ctx.message.author.mention if ctx.message.author.id == "140652945032216576": await self.bot.say(f"yes you are {mention}") else: n = random.randint(0, 1) if n == 1: await self.bot.say("only my master is cool") else: await self.bot.say(f"i guess ill let you be cool this time" f"{mention}") @commands.command(pass_context=True) async def echo(self, ctx, *, something): """bot echos what you say""" await self.bot.say("{}".format(something)) @commands.cooldown(rate=3, per=300, type=commands.BucketType.channel) @commands.command(pass_context=True) async def spam(self, ctx, n, *, something): """&spam number message, max 20""" if int(n) > 10: await self.bot.say("not aloud") else: times = int(n) - 1 while (times >= 0): await self.bot.say("{}".format(something)) times = times - 1 @commands.command(pass_context=True) async def embed(self, ctx, *, message): """bot says what you type in embeded text""" em = discord.Embed(title=str(ctx.message.author), description=message, colour=discord.Colour.green()) await self.bot.say(embed=em) @commands.command(name='8ball') async def eight_ball(self, *, quest=None): responses = ['๐Ÿง€The cheese says it is certain', '๐Ÿง€The cheese says it is decidedly so', '๐Ÿง€The cheese says without a doubt', '๐Ÿง€The cheese says yes definitely', '๐Ÿง€The cheese says you may rely on it', '๐Ÿง€The cheese says as I see it, yes', '๐Ÿง€The cheese says most likely', '๐Ÿง€The cheese says outlook good', '๐Ÿง€The cheese says yes', '๐Ÿง€The cheese says sighns point to yes', '๐Ÿง€The cheese says reply hazy try again', '๐Ÿง€The cheese says ask again later', '๐Ÿง€The cheese says better not tell you now', '๐Ÿง€The cheese says cannot predict now', '๐Ÿง€The cheese says concentrate and ask again', '๐Ÿง€The cheese says don\'t count on it', '๐Ÿง€The cheese says my reply is no', '๐Ÿง€The cheese says my sources say no', '๐Ÿง€The cheese says outlook not so good', '๐Ÿง€The cheese says very doubtful'] if quest is None: await self.bot.say('Ask me a question noob!') else: await self.bot.say(random.choice(responses)) @commands.command(pass_context=True, aliases=['crc']) async def cat_rat_cheese(self, ctx): msg = await self.bot.say('react with your choice, ' 'wait for the 3 reactions to load tho') await self.bot.add_reaction(msg, '๐Ÿ€') await self.bot.add_reaction(msg, '๐Ÿง€') await self.bot.add_reaction(msg, '๐Ÿฑ') bot_score = 0 usr_score = 0 author = ctx.message.author while True: scorestr = f'your score: {usr_score} my score: {bot_score}\n' if bot_score == 3 or usr_score == 3: if usr_score > bot_score: await self.bot.edit_message(msg, scorestr + 'you won best out of 3') break else: await self.bot.edit_message(msg, scorestr + 'bot won best out of 3') break response = await self.bot.wait_for_reaction( emoji=['๐Ÿ€', '๐Ÿง€', '๐Ÿฑ'], user=author, timeout=10, message=msg) bot_choice = random.choice(['๐Ÿ€', '๐Ÿง€', '๐Ÿฑ']) try: response = response.reaction.emoji if response == bot_choice: await self.bot.edit_message(msg, scorestr + 'draw') await self.bot.remove_reaction(msg, response, author) continue elif response == '๐Ÿ€': if bot_choice == '๐Ÿง€': usr_score = usr_score + 1 message = 'bot picked ๐Ÿง€ your rat eats ' \ 'the cheese and you win' await self.bot.edit_message(msg, scorestr + message) await self.bot.remove_reaction(msg, '๐Ÿ€', author) continue else: bot_score = bot_score + 1 message = 'bot picked ๐Ÿฑ my cat eats your rat and i win' await self.bot.edit_message(msg, scorestr + message) await self.bot.remove_reaction(msg, '๐Ÿ€', author) continue elif response == '๐Ÿง€': if bot_choice == '๐Ÿ€': bot_score = bot_score + 1 message = 'bot picked ๐Ÿ€ bots rat eats the cheese ' \ 'and u lose' await self.bot.edit_message(msg, scorestr + message) await self.bot.remove_reaction(msg, '๐Ÿง€', author) continue else: usr_score = usr_score + 1 message = 'bot picked ๐Ÿฑ bots cat eats your cheese ' \ 'but its poisonous so you win' await self.bot.edit_message(msg, scorestr + message) await self.bot.remove_reaction(msg, '๐Ÿง€', author) continue elif response == '๐Ÿฑ': if bot_choice == '๐Ÿ€': usr_score = usr_score + 1 message = 'bot picked ๐Ÿ€ your cat eats the rat so ' \ 'you win' await self.bot.edit_message(msg, scorestr + message) await self.bot.remove_reaction(msg, '๐Ÿฑ', author) continue else: bot_score = bot_score + 1 message = 'bot picked ๐Ÿง€ your cat eats the cheese ' \ 'but gets poisoned and dies i win' await self.bot.edit_message(msg, scorestr + message) await self.bot.remove_reaction(msg, '๐Ÿฑ', author) continue except AttributeError: await self.bot.edit_message(msg, 'too slow') break @commands.group() async def invite(self): pass @commands.has_permissions(administrator=True) @invite.command(pass_context=True) async def temp(self, ctx): inv = await self.bot.create_invite(ctx.message.channel, max_age=600, max_uses=1, temporary=True, unique=True) await self.bot.say(inv) @commands.has_permissions(administrator=True) @invite.command(pass_context=True) async def perm(self, ctx): inv = await self.bot.create_invite(ctx.message.channel, max_age=600, max_uses=1, temporary=False, unique=True) await self.bot.say(inv) class patched_wikia(runescapeapi.runescapeapi._Wikia): def isearch(self, searchTerm: str): ''' returns a generator that iterates though the search results pages ''' for i in wikia.search(self.wiki, searchTerm): if not i.startswith('Transcript'): yield wikia.page(self.wiki, i) # wikia stuffs @commands.group(pass_context=True) async def wikia(self, ctx): pass @wikia.command(pass_context=True) async def setwiki(self, ctx, wiki): self.picked_wikis[ctx.message.author.id] = wiki await self.bot.say('Successfully set your current wikia to: ' f'**{wiki}**') @wikia.command(pass_context=True) async def search(self, ctx, *, query): try: s = self.patched_wikia(self.picked_wikis[ctx.message.author.id]) \ .isearch(query) def next_page(page): em = discord.Embed(title=page.title, description=page.summary, url=page.url.replace(' ', '_')) if page.images != []: em.set_image(url=page.images[0]) return em msg = await self.bot.say(embed=next_page(next(s))) await self.bot.add_reaction(msg, 'โ–ถ') while True: try: await self.bot.wait_for_reaction(emoji='โ–ถ', user=ctx.message.author) await self.bot.remove_reaction(msg, 'โ–ถ', ctx.message.author) await self.bot.edit_message(msg, embed=next_page(next(s))) except StopIteration: await self.bot.say('Thats all the results') break except KeyError: err_msg = 'Please set your current wikia using: ' \ '&wikia setwiki ' \ '' await self.bot.say(err_msg) @wikia.command(pass_context=True) async def page(self, ctx, *, query): try: q = wikia.page(self.picked_wikis[ctx.message.author.id], query) em = discord.Embed(title=q.title, description=q.summary, url=q.url.replace(' ', '_')) if q.images != []: em.set_image(url=q.images[0]) await self.bot.say(embed=em) except KeyError: err_msg = 'Please set your current wikia using: ' \ '&wikia setwiki ' \ '' await self.bot.say(err_msg) @commands.command(pass_context=True) async def b64(self, ctx: commands.context, *, text=None): if text is None: url = ctx.message.attachments[0]['url'] async with aiohttp.ClientSession() as session: async with session.get(url) as r: print(dir(r)) image = await r.read() with open('b64.txt', 'wb') as file: file.write(base64.b64encode(image)) file.close() await self.bot.upload('b64.txt') else: await self.bot.say(base64.b64encode(text.encode('utf-8')) .decode('utf-8')) @commands.command(pass_context=True) async def shutup(self, ctx): def check(msg): return msg.author.id == '388859625585508376' await self.bot.purge_from(ctx.message.channel, check=check) await self.bot.say('**:(**') @commands.command(pass_context=True) async def shell(self, ctx, *, command): if ctx.message.author.id == '140652945032216576': pag = commands.Paginator() out = os.popen(command).read().split('\n') for i in out: try: pag.add_line(line=i) except RuntimeError: pag.close_page() pag.add_line(line=i) for i in pag.pages: await self.bot.say(i) @commands.command() async def git(self): await self.bot.say('https://raatty.club:3000/raatty/robo-rat') def setup(bot): bot.add_cog(bots_commands(bot))