-
Notifications
You must be signed in to change notification settings - Fork 1
/
cogs3.py
95 lines (78 loc) · 3.07 KB
/
cogs3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import discord, random, requests, io, json, aiohttp, re
from bs4 import BeautifulSoup
from discord import ext
from discord.ext import commands
from random import choice, randint
from discord.ext.commands import Bot
import platform, asyncio
class Cog3(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.session = aiohttp.ClientSession()
@commands.command(description="Make fancy text!")
async def fancify(self, ctx, *, text):
def strip_non_ascii(string):
"""Returns the string without non ASCII characters."""
stripped = (c for c in string if 0 < ord(c) < 127)
return "".join(stripped)
text = strip_non_ascii(text)
if len(text.strip()) < 1:
return await self.ctx.send(":x: ASCII characters only please!")
output = ""
for letter in text:
if 65 <= ord(letter) <= 90:
output += chr(ord(letter) + 119951)
elif 97 <= ord(letter) <= 122:
output += chr(ord(letter) + 119919)
elif letter == " ":
output += " "
await ctx.send(output)
@commands.command()
@commands.guild_only()
async def echo(self, ctx, *, message):
"""Makes the bot talk."""
say = message
await ctx.message.delete()
return await ctx.send(say)
@commands.command()
@commands.guild_only()
async def roles(self, ctx):
"""Lists the roles for the current guild"""
roles = ctx.guild.roles
embed = discord.Embed(title="**The roles on this server are: **")
for role in roles:
embed.add_field(name=role.name, value=role.name)
await ctx.send(embed=embed)
@commands.command(description="Really awful jokes. Courtesy of icanhazdadjoke.com")
async def dadjoke(self, ctx):
import requests
channel = ctx.message.channel
author = ctx.message.author
server = ctx.message.guild
joke = requests.get(
"https://icanhazdadjoke.com", headers={"Accept": "text/plain"}
).text
await ctx.send(joke)
@commands.command(aliases=["diceroll", "rolladice"])
async def roll(self, ctx):
"""Roll a Frikin Die"""
await ctx.send("You rolled a " + str(randint(1, 20)))
@commands.bot_has_permissions(attach_files=True)
@commands.command()
async def xkcd(self, ctx):
"""
XKCD
https://xkcd.com/
"""
url = "https://c.xkcd.com/random/comic/"
phrase = r"Image URL \(for hotlinking\/embedding\)\:.*"
async with ctx.typing():
async with self.session.get(url) as response:
soup = BeautifulSoup(await response.text(), "html.parser")
img_url_nav_string = soup.find(text=re.compile(phrase))
img_url = img_url_nav_string.find_next_sibling("a").text
async with self.session.get(img_url) as response:
img = io.BytesIO(await response.read())
await ctx.send(file=discord.File(img, "xkcd.png"))
def setup(bot):
bot.add_cog(Cog3(bot))