-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathFun.py
More file actions
346 lines (302 loc) · 14.8 KB
/
Fun.py
File metadata and controls
346 lines (302 loc) · 14.8 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
import asyncio
import json
import math
import random
import urllib.request
from typing import Optional
from urllib import parse
import discord
import requests
import wikipedia
from aiohttp import request
from bs4 import BeautifulSoup
from discord import Member
from discord.ext import commands
from discord.ext.commands import command
import config
roasts = json.loads(
open('./main_resources/Assets/roast.json', encoding='utf-8').read())['roasts']
kills = json.loads(open('./main_resources/Assets/kill.json',
encoding='utf-8').read())['kills']
class Fun(commands.Cog):
"""Fun commands """
def __init__(self, bot):
self.bot = bot
@commands.command(name="gsearch", aliases=['google', 'search'])
@commands.cooldown(rate=1, per=5.0, type=commands.BucketType.user)
async def gsearch(self, ctx: discord.ext.commands.Context, *, query):
"""Sends top google search result with page description"""
searchInput = "https://google.com/search?q=" + \
parse.quote(query) + \
"&num=2" # Query url for top 2 results
res = requests.get(searchInput) # Gets the google search results page
# Parses the google search results page
soup = BeautifulSoup(res.text, "html.parser")
tag = list(soup.find('div', {'class': 'BNeawe vvjwJb AP7Wnd'}).parent.parent.parent.parent.find('div', {
'class': 'BNeawe s3v9rd AP7Wnd'}).find_all('div', {'class': 'BNeawe s3v9rd AP7Wnd'})) # Creates a list of parsable search results
# Gets the description for the parsable search result
text = ""
for div in tag:
if div.find(text=True, recursive=False) != " " and div.find(text=True, recursive=False) is not None:
text = div.find(text=True, recursive=False)
break
# Creates an embed with the relevant data, ie Result title, its url and its description
embed = discord.Embed(title=soup.find('div', {'class': 'BNeawe vvjwJb AP7Wnd'}).get_text(),
url=soup.find('div', {'class': 'BNeawe vvjwJb AP7Wnd'}).parent.parent.get(
"href").split('=')[1],
description=text)
await ctx.send(embed=embed)
@commands.command(name="8ball", aliases=['ask'])
@commands.cooldown(rate=1, per=3.0, type=commands.BucketType.user)
async def _8ball(self, ctx, *, question):
""" Ask question and get advice from me 🎱"""
responses = ["It is certain.",
"It is decidedly so.",
"Without a doubt.",
"Yes - definitely.",
"You may rely on it.",
"As I see it, yes.",
"Most likely.",
"Outlook good.",
"Yes.",
"Signs point to yes.",
"Reply hazy, try again.",
"Ask again later."
"Better not tell you now.",
"Cannot predict now.",
"Concentrate and ask again.",
"Don't count on it.",
"My reply is no.",
"My sources say no.",
"Outlook not so good.",
"Very doubtful."]
em = discord.Embed(title='Magic 8ball!',
colour=discord.Colour.orange())
em.add_field(name=f"**Question:** {question}",
value=f"**Answer:** {random.choice(responses)}")
await ctx.send(embed=em)
@commands.command(name="urban")
@commands.cooldown(rate=1, per=2.0, type=commands.BucketType.user)
async def urban(self, ctx, *, search: str):
""" Find the 'best' definition to your words 📚"""
async with ctx.channel.typing():
try:
with urllib.request.urlopen(f"https://api.urbandictionary.com/v0/define?term={search}") as url:
url = json.loads(url.read().decode())
except Exception:
return await ctx.send("Urban API returned invalid data... might be down atm.")
if not url:
return await ctx.send("I think the API broke...")
if not len(url["list"]):
return await ctx.send("Couldn't find your search in the dictionary...")
result = sorted(url["list"], reverse=True,
key=lambda g: int(g["thumbs_up"]))[0]
definition = result["definition"]
if len(definition) >= 1000:
definition = definition[:1000]
definition = definition.rsplit(" ", 1)[0]
definition += "..."
definition = definition.replace('[', "").replace("]", "")
em = discord.Embed(
title=f"📚 Definitions for **{result['word']}**", description=f"\n{definition}",
color=discord.Colour.red())
await ctx.send(embed=em)
@commands.command(name="jokes", aliases=["joke", "funjoke"])
@commands.cooldown(rate=1, per=2.0, type=commands.BucketType.user)
async def jokes(self, ctx):
""" Request I'll tell a joke 🤣"""
async with ctx.channel.typing():
try:
with urllib.request.urlopen("https://v2.jokeapi.dev/joke/Any") as url:
url = json.loads(url.read().decode())
def check(author):
def inner_check(message):
return message.author == author
return inner_check
if not url['error']:
if url["type"] == "twopart":
await ctx.send(url['setup'])
ans = await self.bot.wait_for('message', check=check, timeout=30)
if ans.content.lower().strip() == url['delivery'].lower().strip():
await ctx.send('Impresive , correct answer ')
else:
await ctx.send(url['delivery'])
else:
await ctx.send(url['joke'])
except Exception:
return await ctx.send("I am busy dude, I can't think any joke right now")
@commands.command(name="beer")
@commands.cooldown(rate=1, per=2.0, type=commands.BucketType.user)
async def beer(self, ctx, user: discord.Member = None, *, reason: commands.clean_content = ""):
""" Give someone a beer! 🍻 """
if not user or user.id == ctx.author.id:
return await ctx.send(f"**{ctx.author.name}**: paaaarty!🎉🍺")
if user.id == self.bot.user.id:
return await ctx.send("*drinks beer with you* 🍻")
if user.bot:
return await ctx.send(
f"I would love to give beer to the bot **{ctx.author.name}**, but I don't think it will respond to you :/")
beer_offer = f"**{user.name}**, you got a 🍺 offer from **{ctx.author.name}**"
beer_offer = beer_offer + \
f"\n\n**Reason:** {reason}" if reason else beer_offer
msg = await ctx.send(beer_offer)
def reaction_check(m):
if m.message_id == msg.id and m.user_id == user.id and str(m.emoji) == "🍻":
return True
return False
try:
await msg.add_reaction("🍻")
await self.bot.wait_for("raw_reaction_add", timeout=30.0, check=reaction_check)
await msg.edit(content=f"**{user.name}** and **{ctx.author.name}** are enjoying a lovely beer together 🍻")
except asyncio.TimeoutError:
await msg.delete()
await ctx.send(f"well, doesn't seem like **{user.name}** wanted a beer with you **{ctx.author.name}** ;-;")
except discord.Forbidden:
# Yeah so, bot doesn't have reaction permission, drop the "offer" word
beer_offer = f"**{user.name}**, you got a 🍺 from **{ctx.author.name}**"
beer_offer = beer_offer + \
f"\n\n**Reason:** {reason}" if reason else beer_offer
await msg.edit(content=beer_offer)
@commands.command(name="howhot", aliases=["hotcalc", "hot"])
@commands.cooldown(rate=1, per=2.0, type=commands.BucketType.user)
async def howhot(self, ctx, *, user: discord.Member = None):
""" Returns a percent for how hot is a discord user 🥵"""
user = user or ctx.author
random.seed(user.id)
r = random.randint(1, 100)
hot = r / 1.17
if hot > 25:
emoji = "❤"
elif hot > 50:
emoji = "💖"
elif hot > 75:
emoji = "💞"
else:
emoji = "💔"
await ctx.send(f"**{user.name}** is **{hot:.2f}%** hot {emoji}")
@commands.command(name="f")
@commands.cooldown(rate=1, per=2.0, type=commands.BucketType.user)
async def f(self, ctx):
""" Press F to pay respect 🇫 """
try:
await ctx.message.delete()
except:
pass
finally:
await ctx.send(f"**{ctx.author.mention}** has paid their respects")
@commands.command(name="coinflip", aliases=["flip", "coin"])
@commands.cooldown(rate=1, per=2.0, type=commands.BucketType.user)
async def coinflip(self, ctx):
""" Coinflip! :coin: """
coinsides = ["Heads", "Tails"]
await ctx.send(f"**{ctx.author.name}** flipped a coin and got **{random.choice(coinsides)}**!")
@commands.command(name="wiki", aliases=['wikipedia'])
@commands.cooldown(rate=1, per=2.0, type=commands.BucketType.user)
async def wiki(self, ctx, *, querry_: str):
""" Search wikipedia for any information 🔍"""
async with ctx.channel.typing():
try:
results = wikipedia.search(querry_, results=5)
result_summary = wikipedia.summary(results[0])
result_title = results[0]
em = discord.Embed(title=result_title,
color=discord.Color(0xf58742))
em.set_footer(text=result_summary)
# em2.set_footer(text=f'Recommended searches : ' +
# f'{results[1:-1]}'[1:-1])
await ctx.send(embed=em)
# await ctx.send(embed=em2)
except Exception:
await ctx.send("Sorry, I can find " + querry_ + " in Wikipedia")
@commands.command(name="kill")
@commands.cooldown(rate=1, per=2.0, type=commands.BucketType.user)
async def kill(self, ctx, user: Optional[Member]):
""" kill someone ⚰️"""
if not user:
user = ctx.author
await ctx.send(f'{user.display_name} {random.choice(kills)}')
@commands.command(name="roast")
async def roast(self, ctx, user: discord.Member = None):
""" roast someone 🍳"""
if user is None:
user = ctx.author
await ctx.send(f'{user.display_name}, {random.choice(roasts)}')
@commands.command(name="pp", aliases=['ppsize', 'size', 'penis'])
@commands.cooldown(rate=1, per=2.0, type=commands.BucketType.user)
async def pp(self, ctx, member: discord.Member = None):
""" To check pp size 🍆"""
if member is None:
member = ctx.author
i = random.randint(0, 40)
size = "=" * i
em = discord.Embed(color=discord.Colour.blue(),
title="PeePee size calculator")
em.add_field(name=f"{member.display_name}'s penis:eggplant:",
value=f"8{size}D")
await ctx.send(embed=em)
@commands.command(name="howgay", aliases=['how gay', 'gaypercent'])
@commands.cooldown(rate=1, per=2.0, type=commands.BucketType.user)
async def howgay(self, ctx, member: discord.Member = None):
""" To check gayness 🏳️🌈"""
if member is None:
member = ctx.author
user = str(member.id)
s = sum([int(x) for x in user])
per = float((abs(math.sin((s / 18)))) * 100)
if per >= 50:
gay = 'GAY'
else:
gay = "Not Gay"
per = "{:.2f}".format(per)
em = discord.Embed(title=member.display_name,
description=":two_men_holding_hands: gay result:", color=discord.Colour.red())
em.add_field(
name=gay, value=f"{member.display_name} is :rainbow_flag: {per}% gay ")
em.set_thumbnail(url=member.avatar_url)
await ctx.send(embed=em)
@commands.command(name="password", aliases=['pass', 'generator', 'passwordgenerator'])
@commands.cooldown(rate=1, per=2.0, type=commands.BucketType.user)
async def password(self, ctx, amt: int = 8):
""" Get random password in DM 🔒"""
try:
nwpss = []
lst = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '!', '@',
'#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '+', '=', '{', ",", '}', ']',
'[', ';', ':', '<', '>', '?', '/', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '`', '~',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z']
for x in range(amt):
newpass = random.choice(lst)
nwpss.append(newpass)
fnpss = ''.join(nwpss)
await ctx.send(f'{ctx.author} attempting to send you the genereated password in dms.')
await ctx.author.send(f':white_check_mark:Password Generated: {fnpss}')
except Exception as e:
print(e)
@command(name="insult")
@commands.cooldown(rate=1, per=2.0, type=commands.BucketType.user)
async def insult(self, ctx):
""""Returns some evil insults"""
URL = f"https://evilinsult.com/generate_insult.php?lang=en&type=json"
async with request("GET", URL) as res:
if res.status == 200:
evil_insult = await res.json()
await ctx.send(f"{evil_insult['insult']}")
@command(name="say", hidden=True)
@commands.cooldown(rate=1, per=5.0, type=commands.BucketType.user)
async def say(self, ctx: commands.Context, *, message: str):
await ctx.send(message)
@command(name="quote", hidden=True)
@commands.cooldown(rate=1, per=5.0, type=commands.BucketType.user)
async def say(self, ctx: commands.Context):
r = requests.get("hosturl")#put host url here(website that repl gives)
await ctx.send(r.text)
@command(name="addquote", hidden=True)
@commands.cooldown(rate=1, per=5.0, type=commands.BucketType.user)
async def say(self, ctx: commands.Context,quote:str):
r = requests.get(f"hosturl/submit/{quote}")#put host url here(website that repl gives)
await ctx.send(r.text)
def setup(bot):
bot.add_cog(Fun(bot))
# ----------------------------------------------------------------#