diff --git a/bot.py b/bot.py index 81863fe..eecbb31 100644 --- a/bot.py +++ b/bot.py @@ -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") @@ -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") diff --git a/cogs/games.py b/cogs/games.py index 7b75cfb..2c2dc3a 100644 --- a/cogs/games.py +++ b/cogs/games.py @@ -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 @@ -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: @@ -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) @@ -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 diff --git a/cogs/queries.py b/cogs/queries.py index 97d2483..533b09e 100644 --- a/cogs/queries.py +++ b/cogs/queries.py @@ -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)) @@ -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): @@ -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 diff --git a/cogs/voice.py b/cogs/voice.py index 3e438e9..9a478f5 100644 --- a/cogs/voice.py +++ b/cogs/voice.py @@ -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)') @@ -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) @@ -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 diff --git a/config b/config index 3805c4e..3172aba 100644 --- a/config +++ b/config @@ -1,5 +1,5 @@ [messages] -# Trigger for option commands -optionTrigger: ~ # Trigger for regular commands -commandTrigger: ! +commandTrigger: ` +# Trigger for custom commands +customTrigger: !