Skip to content

Commit

Permalink
fixed some voice and encoding errors
Browse files Browse the repository at this point in the history
started define
  • Loading branch information
oyisre committed Sep 2, 2016
1 parent ce52783 commit a751c2b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 25 deletions.
7 changes: 4 additions & 3 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
config.read('config')
# bot_token = config['discord']['BotToken']
command_trigger = config['messages']['commandTrigger']
custom_trigger = config['messages']['customTrigger']
# discord_token = os.environ['DISCORD_TOKEN']
# bing_key = os.environ['BING_API_KEY']

# Bot vars
prefixes = ['`', '?']
c_prefixes = ['`']
description = '''
fun entertainment
'''
# help_attrs = dict()
bot = commands.Bot(command_prefix=prefixes, description=description)
bot = commands.Bot(command_prefix=c_prefixes, description=description)

# Postgres
urllib.parse.uses_netloc.append("postgres")
Expand All @@ -44,7 +45,7 @@ async def on_message(message):
# return
if message.content == '' or message.server is None:
return
elif message.content.startswith(command_trigger):
elif message.content.startswith(custom_trigger):
await custom_command_check(message)
elif message.content.lower() == 'witness me':
await bot.send_message(message.channel, "WITNESSED")
Expand Down
32 changes: 28 additions & 4 deletions cogs/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
class Games:
"""bot games (NOT WORKING YET)
(B) = Can bet on
Bet by starting your command with the bet command
(e.g '`bet 4 flip h' to bet 4 currency that you'll get heads)"""
Bet by adding '$(number)' to the end of a game
(e.g '`flip h $3' to bet 3 currency that you'll get heads)"""

def __init__(self, bot: commands.Bot, conn):
self.bot = bot
Expand All @@ -20,10 +20,16 @@ def __init__(self, bot: commands.Bot, conn):
async def play(self):
await self.bot.say('i dont know how to')

@commands.command()
async def roll(self, dice: str = '1d6'):
@commands.command(pass_context=True)
async def roll(self, ctx):
"""Rolls a dice in NdN format.
(fully copied from the samples hahahahahah)"""
# TODO: fix this
split = ctx.message.content.split()
if len(split) == 1:
dice = '1d6'
else:
dice = split[1]
try:
rolls, limit = map(int, dice.split('d'))
except Exception:
Expand All @@ -33,6 +39,19 @@ async def roll(self, dice: str = '1d6'):
result = ', '.join(str(random.randint(1, limit)) for r in range(rolls))
await self.bot.say(result)

@commands.command(pass_context=True)
async def flip(self, ctx):
print('ok')

@commands.command(pass_context=True)
async def bank(self, ctx):
cur = self.conn.cursor()
cur.execute("SELECT currency FROM bank WHERE user_id = (%s)",
[ctx.message.author.id])
currency = str(cur.fetchone())
self.bot.say(currency)
cur.close()

# TODO: Finish bet command
'''
@commands.command(pass_context=True)
Expand All @@ -45,3 +64,8 @@ async def bet(self, ctx):
except:
await self.bot.say('what are you saying')
'''


def bet_check(message):
print('ok')
return True
34 changes: 23 additions & 11 deletions cogs/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ async def copypasta(self, search=""):
search_urlsafe = urllib.parse.quote_plus(search)
url = 'http://copypasterino.me/search/' + search_urlsafe
async with session.get(url) as r:
json = await r.json()
json = await r.json(encoding='utf-8')
pasta = json[random.randrange(0, len(json))]['pasta']
else:
url = 'http://copypasterino.me/static/all/hot/' + \
str(random.randint(1, 7))
async with session.get(url) as r:
json = await r.json()
json = await r.json(encoding='utf-8')
pasta = json[random.randrange(0, len(json))]['pasta']
"""
url = 'http://copypasterino.me/general/hot/' + str(random.randint(1, 7))
Expand Down Expand Up @@ -136,6 +136,14 @@ async def spelling(self, ctx):
else:
await self.bot.say(output)

@commands.command()
async def define(self, word: str="define", *args):
url = 'http://api.pearson.com/v2/dictionaries/laad3/entries?search=' + word
async with session.get(url) as r:
response = await r.json(encoding='utf-8')
print('test')
#output = ""


class _GetHtmlJs(threading.Thread):
def __init__(self, driver, url):
Expand Down Expand Up @@ -210,16 +218,20 @@ async def after_the_deadline(query, type=0):
response = await r.text()
soup = BeautifulSoup(response, 'html.parser')
output = ""
found_errors = []
for error in soup.find_all('error'):
output += 'Found: "' + error.find('string').text + '". '
suggestions = ""
suggests = error.find_all('option')
for suggest in error.find_all('option'):
suggestions += "/" + suggest.text
if suggestions == "":
suggestions = " No suggestions"
output += error.find('description').text + \
": " + suggestions[1:] + "\n"
error_text = error.find('string')
if error_text not in found_errors:
output += 'Found: "' + error.find('string').text + '". '
found_errors.append(error_text)
suggestions = ""
suggests = error.find_all('option')
for suggest in error.find_all('option'):
suggestions += "/" + suggest.text
if suggestions == "":
suggestions = " No suggestions"
output += error.find('description').text + \
": " + suggestions[1:] + "\n"
return output


Expand Down
7 changes: 3 additions & 4 deletions cogs/voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ async def create_audio_item(self, arguments, query, message=None):
'fixup': "warn"}) as ydl:
try:
ydl_results = ydl.extract_info(query, download=False)
except:
except Exception as e:
print(str(e))
await self.bot.send_message(
message.channel,
'some error (video not found most likely)')
Expand Down Expand Up @@ -324,7 +325,7 @@ async def create_audio_item(self, arguments, query, message=None):
num_tracks=125)
gpmapi.delete_stations([station_id])
else:
song_list = gpmapi.get_station_tracks('IFL', num_tracks=125)
song_list = gpmapi.get_station_tracks('IFL', num_tracks=50)
radio_msg_content = 'starting random radio'
radio_msg = await self.bot.send_message(message.channel,
radio_msg_content)
Expand Down Expand Up @@ -552,8 +553,6 @@ async def play_music_radio(self, ctx):
songs are taken off google play
will only play after the immediate queue is clear"""
msg = ctx.message.content.split(" ", 1)
if len(msg) == 1:
return

if self.voice_connections.get(ctx.message.server.id) is None:
voice_channel = None
Expand Down
6 changes: 3 additions & 3 deletions config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[messages]
# Trigger for option commands
optionTrigger: ~
# Trigger for regular commands
commandTrigger: !
commandTrigger: `
# Trigger for custom commands
customTrigger: !

0 comments on commit a751c2b

Please sign in to comment.