Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext import commands
- from asyncio import sleep
- from random import randint, choice
- from re import match
- from base64 import b64encode as b64en, b64decode as b64de
- import difflib
- def timedelta_milliseconds(td):
- return td.days*86400000 + td.seconds*1000 + td.microseconds/1000
- class Fun:
- def __init__(self, bot):
- self.bot = bot
- @commands.cooldown(rate=1, per=5, type=commands.BucketType.user)
- @commands.command(pass_context=True, aliases="pang peng pong pung \U0001F3D3".split())
- async def ping(self, ctx):
- """Tests the bot's latency."""
- if ctx.message.author.bot: return
- ver = ctx.invoked_with.title()
- conversions = {
- "Pang": "\U0001F52B Peng! You've been hit after ",
- "Peng": "\U0001F52B Pang! You've been hit after ",
- "Ping": "\U0001F3D3 Pong! Took ",
- "Pong": "\U0001F3D3 Ping! Took ",
- "\U0001F3D3": "\U0001F3D3 Took "
- }
- if ver == "Pung":
- raise commands.BadArgument("Sorry, no pung yet...")
- pong = conversions[ver]
- pongmsg = await self.bot.send_message(ctx.message.channel, "Please wait...")
- await self.bot.edit_message(pongmsg, new_content="{}{}ms!".format(pong, str(int(timedelta_milliseconds(pongmsg.timestamp-ctx.message.timestamp)))))
- @commands.command(pass_context=True)
- async def say(self, ctx, *, args):
- """Says what you give it to say."""
- if ctx.message.author.bot: return
- channel = args.split()[0]
- if match("^<#"+"\d"*18+">$", channel):
- args = args.replace(channel, "").lstrip()
- channel = channel.replace("<#", "").replace(">", "")
- await self.bot.send_message(self.bot.get_channel(channel), args.replace("@everyone", "@ everyone").replace("@here","@ here"))
- else:
- await self.bot.say(args.replace("@everyone", "@ everyone").replace("@here","@ here"))
- await self.bot.delete_message(ctx.message)
- @commands.command()
- async def reverse(self, *args):
- """Reverses what you give it.
- Line breaks get removed."""
- await self.bot.say(" ".join(args)[::-1].replace("@everyone", "@ everyone").replace("@here","@ here"))
- @commands.command()
- async def dice(self):
- """Outputs a number between 1 and 6."""
- await self.bot.say(randint(1, 6))
- @commands.command()
- async def coin(self):
- """Flip a coin."""
- await self.bot.say(choice(("Heads", "Tails")))
- @commands.command()
- async def rps(self, *, inp):
- """Play rock paper scissors with me.
- Accepted inputs:
- anything"""
- inp = inp.lower()
- if inp in ("r","p","s","rock","paper","scissors"):
- if inp in ("r", "p", "s"):
- inp = {"r":"rock", "p":"paper", "s":"scissors"}[inp]
- cpu = choice(("rock", "paper", "scissors"))
- if inp == "rock":
- if cpu == "rock":
- res = 0
- elif cpu == "paper":
- res = -1
- elif cpu == "scissors":
- res = 1
- elif inp == "paper":
- if cpu == "rock":
- res = 1
- elif cpu == "paper":
- res = 0
- elif cpu == "scissors":
- res = -1
- elif inp == "scissors":
- if cpu == "rock":
- res = -1
- elif cpu == "paper":
- res = 1
- elif cpu == "scissors":
- res = 0
- await self.bot.say("You: {}\nComputer: {}\n{}".format(inp, cpu, ("It's a draw.", "You won!", "You lost...")[res]))
- else:
- cpu = choice(("rock", "paper", "scissors"))
- await self.bot.say("You: {0}\nComputer: {1}\n{1} wins!".format(inp, cpu))
- @commands.command()
- async def choose(self, *things):
- """Randomly choose an element of the input.
- Syntax: s!choose [elem1]|[elem2]|...\[suffix]"""
- things = " ".join(things)
- try:
- suffix = things.split("\\")[1]
- suffix = things.split("\\")[-1]
- except IndexError:
- suffix = ""
- things = things.split("\\")[0].split("|")
- await self.bot.say(choice(things).replace("@everyone", "@ everyone").replace("@here", "@ here")+suffix.replace("@everyone", "@ everyone").replace("@here","@ here"))
- @commands.command(pass_context=True)
- async def hi(self, ctx):
- """Says hello to you."""
- await self.bot.say("Hello, {}!".format(ctx.message.author.mention))
- @commands.command(pass_context=True)
- @commands.cooldown(rate=1, per=20, type=commands.BucketType.channel)
- async def repeat(self, ctx, num, *text):
- """Repeat a message multiple times.
- Add %count% to the message to get a counter, add %countBackwards% to have it count backwards.
- Add a suffix that gets said after the repeated messages by adding it to the message after a \\
- Syntax: s!repeat <number of repeats> <message>"""
- if not "spam" in ctx.message.channel.name:
- await self.bot.reply("the repeat command is only available in channels with `spam` in the name.")
- return
- text = " ".join(text).replace("@", "@\u200b").split("\\")
- try:
- suffix = text[1]
- suffix = text[-1]
- except IndexError:
- suffix = None
- # print(suffix)
- text = text[0]
- # print(text)
- try:
- num = int(num)
- num = 50 if num > 50 else num
- except ValueError:
- await self.bot.say("Invalid number.")
- return False
- text = text.replace("%count%", "{0}").replace("%countBackwards%", "{1}").replace("%enumerate%", "{2}")
- for i in range(num):
- if str(i+1)[-1:] == "1" and i+1 != 11:
- enumend = "st"
- elif str(i+1)[-1:] == "2" and i+1 != 12:
- enumend = "nd"
- elif str(i+1)[-1:] == "3" and i+1 != 13:
- enumend = "rd"
- else:
- enumend = "th"
- await self.bot.say(text.format(i+1, num-i, str(i+1)+enumend))
- await sleep(2)
- if suffix is not None:
- await self.bot.say(suffix)
- @commands.command(pass_context=True)
- async def typing(self, ctx):
- """Pretends that the bot was typing."""
- await self.bot.send_typing(ctx.message.channel)
- await self.bot.delete_message(ctx.message)
- @commands.command(pass_context=True)
- async def embed(self, ctx, color:discord.Colour, *, text):
- """Creates an embed for you."""
- em = discord.Embed(description=text, colour=color)
- await self.bot.send_message(ctx.message.channel, embed=em)
- await self.bot.delete_message(ctx.message)
- @commands.command(pass_context=True)
- async def emojify(self, ctx, *, text):
- """Turns your text into emojis."""
- o = ""
- for i in text:
- i = i.lower()
- if i in "abcdefghijklmnopqrstuvwxyz":
- o += ":regional_indicator_{}:".format(i)
- elif i == " " and ctx.message.server.me.permissions_in(ctx.message.channel).external_emojis:
- o += "<:regional_indicator_space:321333486256521216>"
- elif i == " ":
- o += i
- elif i in "1234567890":
- if i == "1":
- i = "one"
- elif i == "2":
- i = "two"
- elif i == "3":
- i = "three"
- elif i == "4":
- i = "four"
- elif i == "5":
- i = "five"
- elif i == "6":
- i = "six"
- elif i == "7":
- i = "seven"
- elif i == "8":
- i = "eight"
- elif i == "9":
- i = "nine"
- elif i == "0":
- i = "zero"
- o += ":{}:".format(i)
- elif i == "#":
- o += ":hash:"
- elif i == "*":
- o += ":asterisk:"
- await self.bot.say(o)
- @commands.command(pass_context=True)
- async def emoji(self, ctx, ename):
- """Search an emoji in all servers I know."""
- em = None
- em = discord.utils.find(lambda e: e.name.lower() == ename.lower(), self.bot.get_all_emojis())
- if em is None:
- await self.bot.say("Emoji not found.")
- else:
- await self.bot.say(em)
- await self.bot.delete_message(ctx.message)
- @commands.command(pass_context=True)
- async def memory(self, ctx, time:float=3.0, digits:int=7):
- """Play a memory game.
- I will show a number for a specified time in seconds, and you have to remember and send it."""
- try:
- if time > 5:
- await self.bot.say("Nope, over 5 seconds is too easy")
- return
- if not 0 < digits < 100:
- await self.bot.say("Are you kidding me?")
- return
- num = randint(10**(digits-1), (10**digits)-1)
- await self.bot.say(f"{ctx.message.author.mention}, remember this number:\n{num}", delete_after=time)
- msg = await self.bot.wait_for_message(check=lambda m: m.channel==ctx.message.channel and m.author==ctx.message.author)
- if msg.content == str(num):
- await self.bot.say(f"GG! {num} is right!")
- else:
- await self.bot.say(f"Nope. It was {num}")
- except Exception as e:
- print(type(e).__name__, e)
- @commands.command()
- async def randomchars(self, num:int=10, max:int=0x110000-1):
- """Generate random unicode characters.
- Max is the maximum unicode value a character should have."""
- if not 0 < num < 2001:
- await self.bot.reply('invalid number of characters.')
- return
- if not 0 < num < 0x110000:
- await self.bot.reply('invalid unicode range.')
- return
- await self.bot.say(''.join([chr(randint(0, max)) for i in range(num)]))
- @commands.command()
- async def vaporwave(self, *, text):
- """Turns your text into vaporwave text."""
- o = ""
- for c in text:
- if c == " ":
- c = "\u3000"
- elif ord(c) in range(0x21, 0x7F):
- c = chr(ord(c) + 0xFEE0)
- o += c
- await self.bot.say(o)
- @commands.command()
- async def ship(self, first:discord.User, second:discord.User):
- """Ship people.
- Unlike with those other shipping bots, the results of this command are NOT random, and stable, so they wont change if you run the command again. On the other hand, its extremely rare to find a 100% ship."""
- fmt = """```
- Shipping {0} and {1}...
- Score: {2:.2%}```"""
- res = difflib.SequenceMatcher(None, format(hash(first.id), "x"), format(hash(second.id), "x"))
- await self.bot.say(fmt.format(first.name, second.name, await self.bot.loop.run_in_executor(None, res.ratio), ".2%"))
- def setup(bot):
- bot.add_cog(Fun(bot))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement