Skip to content
This repository was archived by the owner on Jul 31, 2018. It is now read-only.

Commit b34d559

Browse files
authored
Merge pull request #1 from kwugfighter/master
Add files via upload
2 parents b5d497b + f8b147e commit b34d559

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

cogs/kwug.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import discord
2+
from discord.ext import commands
3+
import datetime
4+
import time
5+
import random
6+
import asyncio
7+
import json
8+
import aiohttp
9+
10+
terms=""
11+
definition_number=0
12+
13+
class Random():
14+
15+
def __init__(self, bot):
16+
self.bot = bot
17+
18+
@commands.command(pass_context=True)
19+
async def random(self, ctx, start : int, stop : int):
20+
'''Generates a Random Number Between Two Numbers'''
21+
emb = discord.Embed(title="Your Random Number Is...", description=str(random.randint(start, stop)), color=discord.Color.red())
22+
await self.bot.say(embed=emb)
23+
24+
@commands.command()
25+
async def urban(self, *, search_terms : str):
26+
'''Searches Up a Term in Urban Dictionary'''
27+
search_terms = search_terms.split(" ")
28+
global definition_number
29+
definition_number=0
30+
try:
31+
definition_number = int(search_terms[-1]) - 1
32+
search_terms.remove(search_terms[-1])
33+
except ValueError:
34+
definition_number = 0
35+
if definition_number not in range(0, 11):
36+
pos = 0
37+
search_terms = "+".join(search_terms)
38+
url = "http://api.urbandictionary.com/v0/define?term=" + search_terms
39+
async with aiohttp.get(url) as r:
40+
result = await r.json()
41+
if result["list"]:
42+
definition = result['list'][definition_number]['definition']
43+
example = result['list'][definition_number]['example']
44+
defs = len(result['list'])
45+
global terms
46+
search_terms = search_terms.split("+")
47+
terms=""
48+
for i in search_terms:
49+
terms += i
50+
terms += " "
51+
msg = ("{}\n\n**Example:\n**{}".format(definition, example))
52+
title = (terms + " ({}/{})".format(definition_number+1, defs))
53+
emb = discord.Embed(color = discord.Color.blue(), title = title, description=msg)
54+
await self.bot.say(embed=emb)
55+
else:
56+
await self.bot.say("Your search terms gave no results.")
57+
58+
@commands.command()
59+
async def coinflip(self):
60+
'''Flips a coin'''
61+
flip = random.randint(0,1)
62+
coin = ""
63+
if flip == 0:
64+
coin = "Tail"
65+
elif flip == 1:
66+
coin = "Head"
67+
emb=discord.Embed(title="You Flipped A...", description=coin, color = discord.Color.gold())
68+
await self.bot.say(embed=emb)
69+
def setup(bot):
70+
bot.add_cog(Random(bot))

0 commit comments

Comments
 (0)