From 8993b5988c04c2d273180108e67506e1bb57df70 Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 1 Jun 2017 19:38:13 -0500 Subject: [PATCH 01/16] Fixed server icon command error --- Discord/clients.py | 2 +- Discord/cogs/discord.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Discord/clients.py b/Discord/clients.py index 4f2b7c75e0..147c879432 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -23,7 +23,7 @@ from utilities.help_formatter import CustomHelpFormatter from utilities import errors -version = "0.35.0" +version = "0.35.1" changelog = "https://discord.gg/a2rbZPu" stream_url = "https://www.twitch.tv/harmonbot" owner_id = "115691005197549570" diff --git a/Discord/cogs/discord.py b/Discord/cogs/discord.py index aa68c49ef5..34d20b3641 100644 --- a/Discord/cogs/discord.py +++ b/Discord/cogs/discord.py @@ -347,6 +347,7 @@ async def servericon(self, ctx): '''See a bigger version of the server icon''' if not ctx.message.server.icon: await self.bot.embed_reply(":no_entry: This server doesn't have an icon") + return await self.bot.embed_reply("This server's icon:", image_url = ctx.message.server.icon_url) @commands.command(aliases = ["serverinformation", "server_info", "server_information"], pass_context = True, no_pm = True) From 98d1c2eec7e062758259601c81ff7d3e2f1172b4 Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 1 Jun 2017 19:45:30 -0500 Subject: [PATCH 02/16] Improved blackjack command Added dealer hole card Improved embed response format Added message cleanup Improved response parsing Improved processing efficiency --- Discord/clients.py | 2 +- Discord/cogs/games.py | 84 ++++++++++++++++++++++++++----------------- 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/Discord/clients.py b/Discord/clients.py index 147c879432..57ae03e45e 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -23,7 +23,7 @@ from utilities.help_formatter import CustomHelpFormatter from utilities import errors -version = "0.35.1" +version = "0.35.2" changelog = "https://discord.gg/a2rbZPu" stream_url = "https://www.twitch.tv/harmonbot" owner_id = "115691005197549570" diff --git a/Discord/cogs/games.py b/Discord/cogs/games.py index e31d79fdda..caa3bae1b4 100644 --- a/Discord/cogs/games.py +++ b/Discord/cogs/games.py @@ -308,53 +308,71 @@ async def woodcutting_rate(self, ctx, *, wood_type : str): @commands.command(pass_context = True) @checks.not_forbidden() async def blackjack(self, ctx): - '''Play a game of blackjack''' + ''' + Play a game of blackjack + Manage Messages permission required for message cleanup + ''' + # TODO: S17 deck = pydealer.Deck() deck.shuffle() dealer = deck.deal(2) - hand = deck.deal(2) - dealer_string = self.cards_to_string(dealer.cards) - hand_string = self.cards_to_string(hand.cards) + player = deck.deal(2) + dealer_string = ":grey_question: :{}: {}".format(dealer.cards[1].suit.lower(), dealer.cards[1].value) + player_string = self.cards_to_string(player.cards) dealer_total = self.blackjack_total(dealer.cards) - hand_total = self.blackjack_total(hand.cards) - await self.bot.embed_say("Dealer: {} ({})\n{}: {} ({})".format(dealer_string, dealer_total, ctx.message.author.display_name, hand_string, hand_total)) - await self.bot.embed_reply("Hit or Stay?") + player_total = self.blackjack_total(player.cards) + response, embed = await self.bot.embed_reply("Dealer: {} (?)\n{}: {} ({})\n".format(dealer_string, ctx.message.author.display_name, player_string, player_total), title = "Blackjack", footer_text = "Hit or Stay?") + await self.bot.attempt_delete_message(ctx.message) while True: - action = await self.bot.wait_for_message(author = ctx.message.author, check = lambda msg: msg.content.lower() in ["hit", "stay"]) - if action.content.lower() == "hit": - hand.add(deck.deal()) - hand_string = self.cards_to_string(hand.cards) - hand_total = self.blackjack_total(hand.cards) - await self.bot.embed_say("Dealer: {} ({})\n{}: {} ({})\n".format(dealer_string, dealer_total, ctx.message.author.display_name, hand_string, hand_total)) - if hand_total > 21: - await self.bot.embed_reply(":boom: You have busted\nYou lost :(") - return - else: - await self.bot.embed_reply("Hit or Stay?") + action = await self.bot.wait_for_message(author = ctx.message.author, check = lambda msg: msg.content.lower().strip('!') in ("hit", "stay")) + await self.bot.attempt_delete_message(action) + if action.content.lower().strip('!') == "hit": + player.add(deck.deal()) + player_string = self.cards_to_string(player.cards) + player_total = self.blackjack_total(player.cards) + embed.description = "Dealer: {} (?)\n{}: {} ({})\n".format(dealer_string, ctx.message.author.display_name, player_string, player_total) + await self.bot.edit_message(response, embed = embed) + if player_total > 21: + embed.description += ":boom: You have busted" + embed.set_footer(text = "You lost :(") + break else: + dealer_string = self.cards_to_string(dealer.cards) + embed.description = "Dealer: {} ({})\n{}: {} ({})\n".format(dealer_string, dealer_total, ctx.message.author.display_name, player_string, player_total) if dealer_total > 21: - await self.bot.embed_reply("The dealer busted\nYou win!") - return - elif dealer_total > hand_total: - await self.bot.embed_reply("The dealer beat you\nYou lost :(") - return + embed.description += ":boom: The dealer busted" + embed.set_footer(text = "You win!") + break + elif dealer_total > player_total: + embed.description += "The dealer beat you" + embed.set_footer(text = "You lost :(") + break + embed.set_footer(text = "Dealer's turn..") + await self.bot.edit_message(response, embed = embed) while True: + await asyncio.sleep(5) dealer.add(deck.deal()) dealer_string = self.cards_to_string(dealer.cards) dealer_total = self.blackjack_total(dealer.cards) - await self.bot.embed_say("Dealer: {} ({})\n{}: {} ({})\n".format(dealer_string, dealer_total, ctx.message.author.display_name, hand_string, hand_total)) + embed.description = "Dealer: {} ({})\n{}: {} ({})\n".format(dealer_string, dealer_total, ctx.message.author.display_name, player_string, player_total) + await self.bot.edit_message(response, embed = embed) if dealer_total > 21: - await self.bot.embed_reply("The dealer busted\nYou win!") - return - elif dealer_total > hand_total: - await self.bot.embed_reply("The dealer beat you\nYou lost :(") - return - await asyncio.sleep(5) + embed.description += ":boom: The dealer busted" + embed.set_footer(text = "You win!") + break + elif dealer_total > player_total: + embed.description += "The dealer beat you" + embed.set_footer(text = "You lost :(") + break + elif dealer_total == player_total == 21: + embed.set_footer(text = "It's a push (tie)") + break + break + await self.bot.edit_message(response, embed = embed) def blackjack_total(self, cards): - total = sum([self.blackjack_ranks["values"][card.value] for card in cards]) - if pydealer.tools.find_card(cards, term = "Ace", limit = 1) and total <= 11: - total += 10 + total = sum(self.blackjack_ranks["values"][card.value] for card in cards) + if pydealer.tools.find_card(cards, term = "Ace", limit = 1) and total <= 11: total += 10 return total @commands.group(pass_context = True, invoke_without_command = True) From 05cd7e88298f9fbc2f32fed381c6eb99360e6f65 Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 1 Jun 2017 19:50:16 -0500 Subject: [PATCH 03/16] Unhid invite command --- Discord/clients.py | 2 +- Discord/cogs/meta.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Discord/clients.py b/Discord/clients.py index 57ae03e45e..aa5aedb280 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -23,7 +23,7 @@ from utilities.help_formatter import CustomHelpFormatter from utilities import errors -version = "0.35.2" +version = "0.35.3" changelog = "https://discord.gg/a2rbZPu" stream_url = "https://www.twitch.tv/harmonbot" owner_id = "115691005197549570" diff --git a/Discord/cogs/meta.py b/Discord/cogs/meta.py index 9f7ae3a647..c22c199093 100644 --- a/Discord/cogs/meta.py +++ b/Discord/cogs/meta.py @@ -268,7 +268,7 @@ async def conversions(self, ctx): await self.bot.embed_reply("**Temperature Unit Conversions**: {0}[c, f, k, r, de]__to__[c, f, k, r, de, n, re, ro]\n" "**Weight Unit Conversions**: {0}__to__\nunits: [amu, me, bagc, bagpc, barge, kt, ct, clove, crith, da, drt, drav, ev, gamma, gr, gv, longcwt, cwt, shcwt, kg, kip, mark, mite, mitem, ozt, ozav, oz, dwt, pwt, point, lb, lbav, lbm, lbt, quarterimp, quarterinf, quarterlinf, q, sap, sheet, slug, st, atl, ats, longtn, ton, shtn, t, wey, g]".format(ctx.prefix), title = "Conversion Commands") - @commands.command(aliases = ["oauth"], hidden = True) + @commands.command(aliases = ["oauth"]) async def invite(self): '''Link to invite me to a server''' from clients import application_info From a6f6eee09a651942c59f0b54b4adbbf8efccfca9 Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 1 Jun 2017 19:57:36 -0500 Subject: [PATCH 04/16] Added thousands separator commas for stats command Also adjusted members online format and improved efficiency --- Discord/clients.py | 2 +- Discord/cogs/meta.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Discord/clients.py b/Discord/clients.py index aa5aedb280..7bc5b2bc4b 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -23,7 +23,7 @@ from utilities.help_formatter import CustomHelpFormatter from utilities import errors -version = "0.35.3" +version = "0.35.4" changelog = "https://discord.gg/a2rbZPu" stream_url = "https://www.twitch.tv/harmonbot" owner_id = "115691005197549570" diff --git a/Discord/cogs/meta.py b/Discord/cogs/meta.py index c22c199093..2218f053ae 100644 --- a/Discord/cogs/meta.py +++ b/Discord/cogs/meta.py @@ -301,24 +301,24 @@ async def stats(self, ctx): avatar = ctx.message.author.avatar_url or ctx.message.author.default_avatar_url embed.set_author(name = ctx.message.author.display_name, icon_url = avatar) # url? embed.add_field(name = "Uptime", value = uptime) - embed.add_field(name = "Total Recorded Uptime", value = total_uptime) # since 2016-04-17, fixed 2016-05-10 - embed.add_field(name = "Recorded Restarts", value = stats["restarts"]) # since 2016-04-17, fixed 2016-05-10 + embed.add_field(name = "Total Recorded Uptime", value = total_uptime) ## since 2016-04-17, fixed 2016-05-10 + embed.add_field(name = "Recorded Restarts", value = "{:,}".format(stats["restarts"])) ## since 2016-04-17, fixed 2016-05-10 embed.add_field(name = "Main Commands", value = len(set(self.bot.commands.values()))) embed.add_field(name = "Commands Executed", - value = "{} this session\n{} total recorded".format(session_commands_executed, stats["commands_executed"])) + value = "{} this session\n{:,} total recorded".format(session_commands_executed, stats["commands_executed"])) # since 2016-06-10 (cog commands) - embed.add_field(name = "Cogs Reloaded", value = stats["cogs_reloaded"]) # since 2016-06-10 - implemented cog reloading + embed.add_field(name = "Cogs Reloaded", value = "{:,}".format(stats["cogs_reloaded"])) ## since 2016-06-10 - implemented cog reloading # TODO: cogs reloaded this session embed.add_field(name = "Servers", value = len(self.bot.servers)) embed.add_field(name = "Channels", value = "{} text\n{} voice (playing in {}/{})".format(text_count, voice_count, playing_in_voice_count, in_voice_count)) embed.add_field(name = "Members", - value = "{} total\n{} online\n{} unique\n{} unique online".format(total_members, total_members_online, len(unique_members), unique_members_online)) + value = "{:,} total\n({:,} online)\n{:,} unique\n({:,} online)".format(total_members, total_members_online, len(unique_members), unique_members_online)) embed.add_field(name = "Top Commands Executed", - value = "\n".join(["{} {}".format(uses, command) for command, uses in top_commands[:5]])) # since 2016-11-14 + value = "\n".join("{:,} {}".format(uses, command) for command, uses in top_commands[:5])) ## since 2016-11-14 embed.add_field(name = "(Total Recorded)", - value = "\n".join(["{} {}".format(uses, command) for command, uses in top_commands[5:10]])) # since 2016-11-14 + value = "\n".join("{:,} {}".format(uses, command) for command, uses in top_commands[5:10])) ## since 2016-11-14 if session_top_5: embed.add_field(name = "(This Session)", - value = "\n".join(["{} {}".format(uses, command) for command, uses in session_top_5])) + value = "\n".join("{:,} {}".format(uses, command) for command, uses in session_top_5)) await self.bot.send_message(ctx.message.channel, embed = embed) @commands.command() From feda8acfebb4e47fcc9e9c98de4ad14cfcbc37ea Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 1 Jun 2017 20:01:02 -0500 Subject: [PATCH 05/16] Added say alias for echo command --- Discord/clients.py | 2 +- Discord/cogs/meta.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Discord/clients.py b/Discord/clients.py index 7bc5b2bc4b..7d4537ba6d 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -23,7 +23,7 @@ from utilities.help_formatter import CustomHelpFormatter from utilities import errors -version = "0.35.4" +version = "0.35.5" changelog = "https://discord.gg/a2rbZPu" stream_url = "https://www.twitch.tv/harmonbot" owner_id = "115691005197549570" diff --git a/Discord/cogs/meta.py b/Discord/cogs/meta.py index 2218f053ae..9a3dec4aa0 100644 --- a/Discord/cogs/meta.py +++ b/Discord/cogs/meta.py @@ -477,7 +477,7 @@ async def do(self, ctx, times : int, *, command): for _ in range(times): await self.bot.process_commands(msg) - @commands.group(invoke_without_command = True) + @commands.group(aliases = ["say"], invoke_without_command = True) @checks.is_owner() async def echo(self, *, message): '''Echoes the message''' From 7a56280191664ed69bfdc9f03f9ef9f80d8cc141 Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 1 Jun 2017 20:03:17 -0500 Subject: [PATCH 06/16] Improved poke command Added message cleanup Fixed duplicate counter issue by writing to file earlier --- Discord/clients.py | 2 +- Discord/cogs/misc.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Discord/clients.py b/Discord/clients.py index 7d4537ba6d..f8e96f5df6 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -23,7 +23,7 @@ from utilities.help_formatter import CustomHelpFormatter from utilities import errors -version = "0.35.5" +version = "0.35.6" changelog = "https://discord.gg/a2rbZPu" stream_url = "https://www.twitch.tv/harmonbot" owner_id = "115691005197549570" diff --git a/Discord/cogs/misc.py b/Discord/cogs/misc.py index 1b50703246..e414a5f43b 100644 --- a/Discord/cogs/misc.py +++ b/Discord/cogs/misc.py @@ -105,14 +105,14 @@ async def poke(self, ctx, *, user : str): with open("data/user_data/{}/pokes.json".format(ctx.message.author.id), 'r') as pokes_file: pokes_data = json.load(pokes_file) pokes_data[to_poke.id] = pokes_data.get(to_poke.id, 0) + 1 + with open("data/user_data/{}/pokes.json".format(ctx.message.author.id), 'w') as pokes_file: + json.dump(pokes_data, pokes_file, indent = 4) embed = discord.Embed(color = clients.bot_color) - avatar = ctx.message.author.default_avatar_url if not ctx.message.author.avatar else ctx.message.author.avatar_url - embed.set_author(name = ctx.message.author, icon_url = avatar) + embed.set_author(name = ctx.message.author, icon_url = ctx.message.author.avatar_url or ctx.message.author.default_avatar_url) embed.description = "Poked you for the {} time!".format(clients.inflect_engine.ordinal(pokes_data[to_poke.id])) await self.bot.send_message(to_poke, embed = embed) - await self.bot.embed_reply("You have poked {} for the {} time!".format(to_poke.mention, clients.inflect_engine.ordinal(pokes_data[to_poke.id]))) - with open("data/user_data/{}/pokes.json".format(ctx.message.author.id), 'w') as pokes_file: - json.dump(pokes_data, pokes_file, indent = 4) + await self.bot.embed_reply("You have poked {} for the {} time!".format(to_poke.mention, clients.inflect_engine.ordinal(pokes_data[to_poke.id])), footer_text = "In response to: {}".format(ctx.message.clean_content)) + await self.bot.attempt_delete_message(ctx.message) def emote_wrapper(name, emote = None): if emote is None: emote = name From 5d1eb1f4300c20ab47b60aa9d58fd6c66420f7aa Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 1 Jun 2017 20:05:02 -0500 Subject: [PATCH 07/16] Added horse and cow emote commands --- Discord/clients.py | 2 +- Discord/cogs/misc.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Discord/clients.py b/Discord/clients.py index f8e96f5df6..3017426e2f 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -23,7 +23,7 @@ from utilities.help_formatter import CustomHelpFormatter from utilities import errors -version = "0.35.6" +version = "0.35.7" changelog = "https://discord.gg/a2rbZPu" stream_url = "https://www.twitch.tv/harmonbot" owner_id = "115691005197549570" diff --git a/Discord/cogs/misc.py b/Discord/cogs/misc.py index e414a5f43b..45887fe4e9 100644 --- a/Discord/cogs/misc.py +++ b/Discord/cogs/misc.py @@ -122,8 +122,9 @@ async def emote_command(self): await self.bot.embed_reply(":{}:".format(emote)) return emote_command -for emote in ("fish", "frog", "turtle", "gun", "tomato", "cucumber", "eggplant", "lizard", "minidisc"): +for emote in ("fish", "frog", "turtle", "gun", "tomato", "cucumber", "eggplant", "lizard", "minidisc", "horse"): setattr(Misc, emote, emote_wrapper(emote)) setattr(Misc, "dog", emote_wrapper("dog", emote = "dog2")) setattr(Misc, "bunny", emote_wrapper("bunny", emote = "rabbit2")) +setattr(Misc, "cow", emote_wrapper("cow", emote = "cow2")) From 31017eb5f9019ecfcfe07a748e764fa973ba4d1c Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 1 Jun 2017 20:09:52 -0500 Subject: [PATCH 08/16] Added additional timeout error handling to dice command --- Discord/clients.py | 2 +- Discord/cogs/random.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Discord/clients.py b/Discord/clients.py index 3017426e2f..46cf57feb7 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -23,7 +23,7 @@ from utilities.help_formatter import CustomHelpFormatter from utilities import errors -version = "0.35.7" +version = "0.35.8" changelog = "https://discord.gg/a2rbZPu" stream_url = "https://www.twitch.tv/harmonbot" owner_id = "115691005197549570" diff --git a/Discord/cogs/random.py b/Discord/cogs/random.py index 58ec88b56f..2751cebf80 100644 --- a/Discord/cogs/random.py +++ b/Discord/cogs/random.py @@ -194,7 +194,7 @@ async def dice(self, *, input : str = '6'): await self.bot.embed_reply(":no_entry: Output too long") except pyparsing.ParseException: await self.bot.embed_reply(":no_entry: Invalid input") - except concurrent.futures.TimeoutError: + except (concurrent.futures.TimeoutError, multiprocessing.context.TimeoutError): await self.bot.embed_reply(":no_entry: Execution exceeded time limit") @commands.command(pass_context = True) From b43295fea1f2f9f3688ee09dfa5a3d4649a13d8f Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 1 Jun 2017 20:14:24 -0500 Subject: [PATCH 09/16] Changed amazon command url to smile --- Discord/clients.py | 2 +- Discord/cogs/search.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Discord/clients.py b/Discord/clients.py index 46cf57feb7..bd4102f66f 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -23,7 +23,7 @@ from utilities.help_formatter import CustomHelpFormatter from utilities import errors -version = "0.35.8" +version = "0.35.9" changelog = "https://discord.gg/a2rbZPu" stream_url = "https://www.twitch.tv/harmonbot" owner_id = "115691005197549570" diff --git a/Discord/cogs/search.py b/Discord/cogs/search.py index 687f395574..5ff414d017 100644 --- a/Discord/cogs/search.py +++ b/Discord/cogs/search.py @@ -76,7 +76,7 @@ async def youtube_error(self, error, ctx): @checks.not_forbidden() async def amazon(self, *search : str): '''Search with Amazon''' - await self.bot.embed_reply("[Amazon search for \"{}\"](https://www.amazon.com/s/?field-keywords={})".format(' '.join(search), '+'.join(search))) + await self.bot.embed_reply("[Amazon search for \"{}\"](https://smile.amazon.com/s/?field-keywords={})".format(' '.join(search), '+'.join(search))) @commands.command() @checks.not_forbidden() From fd802a7727f43336188c49d23594234a57e527dd Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 1 Jun 2017 20:17:42 -0500 Subject: [PATCH 10/16] Fixed fact command Necessary due to API change --- Discord/clients.py | 2 +- Discord/cogs/random.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Discord/clients.py b/Discord/clients.py index bd4102f66f..63b32dc3a8 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -23,7 +23,7 @@ from utilities.help_formatter import CustomHelpFormatter from utilities import errors -version = "0.35.9" +version = "0.35.10" changelog = "https://discord.gg/a2rbZPu" stream_url = "https://www.twitch.tv/harmonbot" owner_id = "115691005197549570" diff --git a/Discord/cogs/random.py b/Discord/cogs/random.py index 2751cebf80..976b27074d 100644 --- a/Discord/cogs/random.py +++ b/Discord/cogs/random.py @@ -219,7 +219,8 @@ async def day(self): @checks.not_forbidden() async def fact(self): '''Random fact''' - async with clients.aiohttp_session.get("http://mentalfloss.com/api/1.0/views/amazing_facts.json?limit=1&bypass=1") as resp: + url = "http://mentalfloss.com/api/1.0/views/amazing_facts.json?limit=1&bypass={}".format(random.random()) + async with clients.aiohttp_session.get(url) as resp: data = await resp.json() await self.bot.embed_reply(BeautifulSoup(data[0]["nid"]).text) From e899f3e87f63dfbee24c7591f095987c7bbda3dc Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 1 Jun 2017 20:19:00 -0500 Subject: [PATCH 11/16] Added tag expunge command --- Discord/clients.py | 2 +- Discord/cogs/tools.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Discord/clients.py b/Discord/clients.py index 63b32dc3a8..cefee97541 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -23,7 +23,7 @@ from utilities.help_formatter import CustomHelpFormatter from utilities import errors -version = "0.35.10" +version = "0.35.11" changelog = "https://discord.gg/a2rbZPu" stream_url = "https://www.twitch.tv/harmonbot" owner_id = "115691005197549570" diff --git a/Discord/cogs/tools.py b/Discord/cogs/tools.py index e6caf4da60..308b025d69 100644 --- a/Discord/cogs/tools.py +++ b/Discord/cogs/tools.py @@ -601,6 +601,19 @@ async def tag_delete(self, ctx, tag : str): json.dump(self.tags_data, tags_file, indent = 4) await self.bot.embed_reply(":ok_hand::skin-tone-2: Your tag has been deleted") + @tag.command(name = "expunge", pass_context = True) + @checks.is_owner() + async def tag_expunge(self, ctx, owner : discord.Member, tag : str): + '''Delete someone else's tags''' + try: + del self.tags_data[owner.id]["tags"][tag] + except KeyError: + await self.bot.embed_reply(":no_entry: Tag not found") + return + with open("data/tags.json", 'w') as tags_file: + json.dump(self.tags_data, tags_file, indent = 4) + await self.bot.embed_reply(":ok_hand::skin-tone-2: {}'s tag has been deleted".format(owner.mention)) + @tag.command(name = "search", aliases = ["contains", "find"], pass_context = True) async def tag_search(self, ctx, *, search : str): '''Search your tags''' From cddde10af532be4667cdea89a4fb69862a94e2eb Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 1 Jun 2017 20:20:29 -0500 Subject: [PATCH 12/16] Fixed tag delete command error when tag not found --- Discord/clients.py | 2 +- Discord/cogs/tools.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Discord/clients.py b/Discord/clients.py index cefee97541..8c08102d13 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -23,7 +23,7 @@ from utilities.help_formatter import CustomHelpFormatter from utilities import errors -version = "0.35.11" +version = "0.35.12" changelog = "https://discord.gg/a2rbZPu" stream_url = "https://www.twitch.tv/harmonbot" owner_id = "115691005197549570" diff --git a/Discord/cogs/tools.py b/Discord/cogs/tools.py index 308b025d69..4851256823 100644 --- a/Discord/cogs/tools.py +++ b/Discord/cogs/tools.py @@ -596,7 +596,11 @@ async def tag_delete(self, ctx, tag : str): '''Delete one of your tags''' if (await self.check_no_tags(ctx)): return if (await self.check_no_tag(ctx, tag)): return - del self.tags_data[ctx.message.author.id]["tags"][tag] + try: + del self.tags_data[ctx.message.author.id]["tags"][tag] + except KeyError: + await self.bot.embed_reply(":no_entry: Tag not found") + return with open("data/tags.json", 'w') as tags_file: json.dump(self.tags_data, tags_file, indent = 4) await self.bot.embed_reply(":ok_hand::skin-tone-2: Your tag has been deleted") From 5cad88941f8d02a5387994117f5d2880468470c4 Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 1 Jun 2017 20:24:11 -0500 Subject: [PATCH 13/16] Added additional error handling for when updating Discord Bots stats 500 (Internal Server Error) and 522 (Cloudflare Error) --- Discord/clients.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Discord/clients.py b/Discord/clients.py index 8c08102d13..4fc4246694 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -23,7 +23,7 @@ from utilities.help_formatter import CustomHelpFormatter from utilities import errors -version = "0.35.12" +version = "0.35.13" changelog = "https://discord.gg/a2rbZPu" stream_url = "https://www.twitch.tv/harmonbot" owner_id = "115691005197549570" @@ -285,7 +285,8 @@ async def _update_discord_bots_stats(): async with aiohttp_session.post("https://bots.discord.pw/api/bots/{}/stats".format(client.user.id), headers = {"authorization": credentials.discord_bots_api_token, "content-type": "application/json"}, data = json.dumps({"server_count": len(client.servers)})) as resp: - if resp.status in (502, 504): + # Change to check for 200? + if resp.status in (500, 502, 504, 522): return "Error: {}".format(resp.status) response = await resp.json() return response From 6371bfd67ceb95950c662adf5edaa69273cee2b5 Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 1 Jun 2017 20:25:58 -0500 Subject: [PATCH 14/16] Added exception text to bad argument error response --- Discord/Harmonbot.py | 2 +- Discord/clients.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Discord/Harmonbot.py b/Discord/Harmonbot.py index 26cde519b5..691e0890d4 100644 --- a/Discord/Harmonbot.py +++ b/Discord/Harmonbot.py @@ -329,7 +329,7 @@ async def on_command_error(error, ctx): elif isinstance(error, errors.NotPermitted): embed.description = ":no_entry: You don't have permission to use that command here" elif isinstance(error, commands.errors.BadArgument): - embed.description = ":no_entry: Error: invalid input" + embed.description = ":no_entry: Error: Invalid Input: {}".format(error) elif isinstance(error, commands.errors.CommandInvokeError) and isinstance(error.original, discord.errors.HTTPException) and str(error.original) == "BAD REQUEST (status code: 400): You can only bulk delete messages that are under 14 days old.": embed.description = ":no_entry: Error: You can only bulk delete messages that are under 14 days old" if embed.description: diff --git a/Discord/clients.py b/Discord/clients.py index 4fc4246694..af4f8ea4b9 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -23,7 +23,7 @@ from utilities.help_formatter import CustomHelpFormatter from utilities import errors -version = "0.35.13" +version = "0.35.14" changelog = "https://discord.gg/a2rbZPu" stream_url = "https://www.twitch.tv/harmonbot" owner_id = "115691005197549570" From d00e6da541c2427f7cea43abc80e8353d7279d37 Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 1 Jun 2017 20:27:08 -0500 Subject: [PATCH 15/16] Fixed translate commands for multiple words --- Discord/clients.py | 2 +- Discord/cogs/resources.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Discord/clients.py b/Discord/clients.py index af4f8ea4b9..4abe72f305 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -23,7 +23,7 @@ from utilities.help_formatter import CustomHelpFormatter from utilities import errors -version = "0.35.14" +version = "0.35.15" changelog = "https://discord.gg/a2rbZPu" stream_url = "https://www.twitch.tv/harmonbot" owner_id = "115691005197549570" diff --git a/Discord/cogs/resources.py b/Discord/cogs/resources.py index e955372e01..6c0660b497 100644 --- a/Discord/cogs/resources.py +++ b/Discord/cogs/resources.py @@ -1196,9 +1196,9 @@ async def translate_to(self, language_code : str, *, text : str): await self.process_translate(text, language_code) async def process_translate(self, text, to_language_code, from_language_code = None): - url = "https://translate.yandex.net/api/v1.5/tr.json/translate?key={}&lang={}&text={}&options=1".format(credentials.yandex_translate_api_key, to_language_code if not from_language_code else "{}-{}".format(from_language_code, to_language_code), text) + url = "https://translate.yandex.net/api/v1.5/tr.json/translate?key={}&lang={}&text={}&options=1".format(credentials.yandex_translate_api_key, to_language_code if not from_language_code else "{}-{}".format(from_language_code, to_language_code), text.replace(' ', '+')) async with clients.aiohttp_session.get(url) as resp: - if resp.status == 400: + if resp.status == 400: # Bad Request await self.bot.embed_reply(":no_entry: Error") return data = await resp.json() From 887a7d4ec23ed5953afc8d869fc48094ae4184bc Mon Sep 17 00:00:00 2001 From: Harmon Date: Thu, 1 Jun 2017 20:31:01 -0500 Subject: [PATCH 16/16] Overhauled joke command to use local csv joke database --- Discord/clients.py | 2 +- Discord/cogs/random.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Discord/clients.py b/Discord/clients.py index 4abe72f305..ef3acafce3 100644 --- a/Discord/clients.py +++ b/Discord/clients.py @@ -23,7 +23,7 @@ from utilities.help_formatter import CustomHelpFormatter from utilities import errors -version = "0.35.15" +version = "0.35.16" changelog = "https://discord.gg/a2rbZPu" stream_url = "https://www.twitch.tv/harmonbot" owner_id = "115691005197549570" diff --git a/Discord/cogs/random.py b/Discord/cogs/random.py index 976b27074d..53acc691aa 100644 --- a/Discord/cogs/random.py +++ b/Discord/cogs/random.py @@ -6,6 +6,7 @@ from bs4 import BeautifulSoup import calendar import concurrent.futures +import csv import datetime import dice import inspect @@ -41,6 +42,15 @@ def __init__(self, bot): self.random_subcommands = ((self.color, "Resources.color"), (self.giphy, "Resources.giphy"), (self.map, "Resources.map"), (self.streetview, "Resources.streetview"), (self.uesp, "Search.uesp"), (self.wikipedia, "Search.wikipedia"), (self.xkcd, "Resources.xkcd")) for command, parent_name in self.random_subcommands: utilities.add_as_subcommand(self, command, parent_name, "random") + # Import jokes + self.jokes = [] + try: + with open("data/jokes.csv", newline = "") as jokes_file: + jokes_reader = csv.reader(jokes_file) + for row in jokes_reader: + self.jokes.append(row[0]) + except FileNotFoundError: + pass def __unload(self): for command, parent_name in self.random_subcommands: @@ -294,9 +304,10 @@ async def insult(self): @checks.not_forbidden() async def joke(self): '''Random joke''' - async with clients.aiohttp_session.get("http://tambal.azurewebsites.net/joke/random") as resp: - data = await resp.json() - await self.bot.embed_reply(data["joke"]) + # Sources: + # https://github.com/KiaFathi/tambalAPI + # https://www.kaggle.com/abhinavmoudgil95/short-jokes (https://github.com/amoudgl/short-jokes-dataset) + await self.bot.embed_reply(random.choice(self.jokes)) @commands.command() @checks.not_forbidden()