From 4cb531ab873c26b796a29ee00cfb6aab815256ae Mon Sep 17 00:00:00 2001 From: Bobloy Date: Tue, 15 May 2018 09:14:11 -0400 Subject: [PATCH] [Snap-Ons] More converted cogs --- recyclingplant/info.json | 4 +- recyclingplant/recyclingplant.py | 2 +- rpsls/__init__.py | 5 ++ rpsls/info.json | 21 ++++++ rpsls/rpsls.py | 90 ++++++++++++++++++++++++ scp/__init__.py | 5 ++ scp/info.json | 20 ++++++ scp/scp.py | 116 +++++++++++++++++++++++++++++++ unicode/info.json | 11 +++ unicode/unicode.py | 53 ++++++++++++++ 10 files changed, 324 insertions(+), 3 deletions(-) create mode 100644 rpsls/__init__.py create mode 100644 rpsls/info.json create mode 100644 rpsls/rpsls.py create mode 100644 scp/__init__.py create mode 100644 scp/info.json create mode 100644 scp/scp.py create mode 100644 unicode/info.json create mode 100644 unicode/unicode.py diff --git a/recyclingplant/info.json b/recyclingplant/info.json index 62ac5df..3ad2e58 100644 --- a/recyclingplant/info.json +++ b/recyclingplant/info.json @@ -10,9 +10,9 @@ ], "description": "Apply for a job at the recycling plant! Sort out the garbage!", "hidden": false, - "install_msg": "Thank you for installing LoveCalculator. Stary recycling today!", + "install_msg": "Thank you for installing RecyclingPlant. Start recycling today with `[p]recyclingplant`", "requirements": [], - "short": "ply for a job at the recycling plant!", + "short": "Apply for a job at the recycling plant!", "tags": [ "bobloy", "environment", diff --git a/recyclingplant/recyclingplant.py b/recyclingplant/recyclingplant.py index b4c0d98..ce56eda 100644 --- a/recyclingplant/recyclingplant.py +++ b/recyclingplant/recyclingplant.py @@ -18,7 +18,7 @@ class RecyclingPlant: with open(self.junk_path) as json_data: self.junk = json.load(json_data) - @commands.command() + @commands.command(aliases=["recycle"]) async def recyclingplant(self, ctx: commands.Context): """Apply for a job at the recycling plant!""" x = 0 diff --git a/rpsls/__init__.py b/rpsls/__init__.py new file mode 100644 index 0000000..46a1600 --- /dev/null +++ b/rpsls/__init__.py @@ -0,0 +1,5 @@ +from .rpsls import RPSLS + + +def setup(bot): + bot.add_cog(RPSLS(bot)) diff --git a/rpsls/info.json b/rpsls/info.json new file mode 100644 index 0000000..fae70d3 --- /dev/null +++ b/rpsls/info.json @@ -0,0 +1,21 @@ +{ + "author": [ + "Bobloy", + "SnappyDragon" + ], + "bot_version": [ + 3, + 0, + 0 + ], + "description": "Play Rock Papers Scissor Lizard Spock by Sam Kass in Discord!", + "hidden": false, + "install_msg": "Thank you for installing RPSLP. Get started with `[p]rpsls`", + "requirements": [], + "short": "Play Rock Papers Scissor Lizard Spock in Discord!", + "tags": [ + "bobloy", + "star trek", + "games" + ] +} \ No newline at end of file diff --git a/rpsls/rpsls.py b/rpsls/rpsls.py new file mode 100644 index 0000000..7257dc2 --- /dev/null +++ b/rpsls/rpsls.py @@ -0,0 +1,90 @@ +import asyncio +import random + +import discord +from redbot.core import commands + + +class RPSLS: + """Play Rock Paper Scissors Lizard Spock.""" + + weaknesses = { + "rock": [ + "paper", + "spock" + ], + "paper": [ + "scissors", + "lizard" + ], + "scissors": [ + "spock", + "rock" + ], + "lizard": [ + "scissors", + "rock" + ], + "spock": [ + "paper", + "lizard" + ] + } + + def __init__(self, bot): + self.bot = bot + + @commands.command() + async def rpsls(self, ctx: commands.Context, choice: str): + """ + Play Rock Paper Scissors Lizard Spock by Sam Kass in Discord! + + Rules: + Scissors cuts Paper + Paper covers Rock + Rock crushes Lizard + Lizard poisons Spock + Spock smashes Scissors + Scissors decapitates Lizard + Lizard eats Paper + Paper disproves Spock + Spock vaporizes Rock + And as it has always Rock crushes Scissors + """ + + player_choice = choice.lower() + player_emote = self.get_emote(player_choice) + if player_emote is None: + await ctx.maybe_send_embed("Invalid Choice") + return + + bot_choice = random.choice(self.weaknesses) + bot_emote = self.get_emote(bot_choice) + message = '{} vs. {}, who will win?'.format(player_emote, bot_emote) + em = discord.Embed(description=message, color=discord.Color.blue()) + await ctx.send(embed=em) + await asyncio.sleep(2) + if player_choice in self.weaknesses[bot_choice]: + message = 'You win! :sob:' + em_color = discord.Color.green() + elif bot_choice in self.weaknesses[player_choice]: + message = 'I win! :smile:' + em_color = discord.Color.red() + else: + message = 'It\'s a draw! :neutral_face:' + em_color = discord.Color.blue() + em = discord.Embed(description=message, color=em_color) + await ctx.send(embed=em) + + def get_emote(self, choice): + if choice == 'rock': + emote = ':moyai:' + elif choice == 'spock': + emote = ':vulcan:' + elif choice == 'paper': + emote = ':page_facing_up:' + elif choice in ['scissors', 'lizard']: + emote = ':{}:'.format(choice) + else: + emote = None + return emote diff --git a/scp/__init__.py b/scp/__init__.py new file mode 100644 index 0000000..bded2a5 --- /dev/null +++ b/scp/__init__.py @@ -0,0 +1,5 @@ +from .scp import SCP + + +def setup(bot): + bot.add_cog(SCP(bot)) diff --git a/scp/info.json b/scp/info.json new file mode 100644 index 0000000..a351508 --- /dev/null +++ b/scp/info.json @@ -0,0 +1,20 @@ +{ + "author": [ + "Bobloy", + "SnappyDragon" + ], + "bot_version": [ + 3, + 0, + 0 + ], + "description": "Look up SCP articles. Warning: Some of them may be too creepy or gruesome.", + "hidden": false, + "install_msg": "You are now connected to the SCP database. You may now proceed to access the data using `[p]help SCP`", + "requirements": [], + "short": "Look up SCP articles.", + "tags": [ + "bobloy", + "gruesom" + ] +} \ No newline at end of file diff --git a/scp/scp.py b/scp/scp.py new file mode 100644 index 0000000..7e64734 --- /dev/null +++ b/scp/scp.py @@ -0,0 +1,116 @@ +import discord +from redbot.core import commands + + +class SCP: + """Look up SCP articles. Warning: Some of them may be too creepy or gruesome.""" + + def __init__(self, bot): + self.bot = bot + + @commands.command() + async def scp(self, ctx: commands.Context, num: int): + """Look up SCP articles. + + Warning: Some of them may be too creepy or gruesome. + Reminder: You must specify a number between 1 and 3999. + """ + + # Thanks Shigbeard and Redjumpman for helping me! + + if 0 < num <= 3999: + msg = "http://www.scp-wiki.net/scp-{:03}".format(num) + c = discord.Color.green() + else: + msg = "You must specify a number between 1 and 3999." + c = discord.Color.red() + + if ctx.embed_requested(): + await ctx.send(embed=discord.Embed(description=msg, color=c)) + else: + await ctx.maybe_send_embed(msg) + + @commands.command() + async def scpj(self, ctx: commands.Context, joke: str): + """Look up SCP-Js. + + Reminder: Enter the correct name or else the resultant page will be invalid. + Use 001, etc. in case of numbers less than 100. + """ + + msg = "http://www.scp-wiki.net/scp-{}-j".format(joke) + await ctx.maybe_send_embed(msg) + + @commands.command() + async def scparc(self, ctx: commands.Context, num: int): + """Look up SCP archives. + + Warning: Some of them may be too creepy or gruesome.""" + valid_archive = ( + 13, 48, 51, 89, 91, 112, 132, 138, 157, 186, 232, 234, + 244, 252, 257, 338, 356, 361, 400, 406, 503, 515, 517, + 578, 728, 744, 776, 784, 837, 922, 987, 1023) + if num in valid_archive: + msg = "http://www.scp-wiki.net/scp-{:03}-arc".format(num) + c = discord.Color.green() + em = discord.Embed(description=msg, color=c) + else: + ttl = "You must specify a valid archive number." + msg = "{}".format(valid_archive) + c = discord.Color.red() + + em = discord.Embed(title=ttl, description=msg, color=c) + + if ctx.embed_requested(): + await ctx.send(embed=em) + else: + await ctx.maybe_send_embed(msg) + + @commands.command() + async def scpex(self, ctx: commands.Context, num: int): + """Look up explained SCP articles. + + Warning: Some of them may be too creepy or gruesome. + """ + + valid_archive = (711, 920, 1841, 1851, 1974, 2600, 4023, 8900) + if num in valid_archive: + msg = "http://www.scp-wiki.net/scp-{:03}-ex".format(num) + c = discord.Color.green() + em = discord.Embed(description=msg, color=c) + else: + ttl = "You must specify a valid archive number." + msg = "{}".format(valid_archive) + c = discord.Color.red() + + em = discord.Embed(title=ttl, description=msg, color=c) + + if ctx.embed_requested(): + await ctx.send(embed=em) + else: + await ctx.maybe_send_embed(msg) + + @commands.command() + async def anomalousitems(self, ctx: commands.Context): + """Look through the log of anomalous items.""" + + msg = "http://www.scp-wiki.net/log-of-anomalous-items" + await ctx.maybe_send_embed(msg) + + @commands.command() + async def extranormalevents(self, ctx: commands.Context): + """Look through the log of extranormal events.""" + + msg = "http://www.scp-wiki.net/log-of-extranormal-events" + await ctx.maybe_send_embed(msg) + + @commands.command() + async def unexplainedlocations(self, ctx: commands.Context): + """Look through the log of unexplained locations.""" + + msg = "http://www.scp-wiki.net/log-of-unexplained-locations" + await ctx.maybe_send_embed(msg) + + +def setup(bot): + bot.add_cog(SCP(bot)) diff --git a/unicode/info.json b/unicode/info.json new file mode 100644 index 0000000..bec3640 --- /dev/null +++ b/unicode/info.json @@ -0,0 +1,11 @@ +{ + "AUTHOR": "SnappyDragon", + "INSTALL_MSG": "\u0048\u0065\u006c\u006c\u006f\u0021 \u0054\u0068\u0069\u0073 \u006d\u0065\u0073\u0073\u0061\u0067\u0065 \u0077\u0061\u0073 \u0077\u0072\u0069\u0074\u0074\u0065\u006e \u0069\u006e \u0055\u004e\u0049\u0043\u004f\u0044\u0045\u002e", + "NAME": "Unicode", + "SHORT": "Encode/Decode Unicode characters!", + "DESCRIPTION": "Encode/Decode a Unicode character!", + "TAGS": [ + "utility", + "utlities" + ] +} diff --git a/unicode/unicode.py b/unicode/unicode.py new file mode 100644 index 0000000..eaeebbf --- /dev/null +++ b/unicode/unicode.py @@ -0,0 +1,53 @@ +import codecs as c + +import discord +from discord.ext import commands + + +class Unicode: + """Encode/Decode Unicode characters!""" + + def __init__(self, bot): + self.bot = bot + + @commands.group(name='unicode', pass_context=True) + async def unicode(self, context): + """Encode/Decode a Unicode character.""" + if context.invoked_subcommand is None: + await self.bot.send_cmd_help(context) + + @unicode.command() + async def decode(self, character): + """Decode a Unicode character.""" + try: + data = 'U+{:04X}'.format(ord(character[0])) + color = discord.Color.green() + except ValueError: + data = '' + color = discord.Color.red() + em = discord.Embed(title=character, description=data, color=color) + await self.bot.say(embed=em) + + @unicode.command() + async def encode(self, character): + """Encode an Unicode character.""" + try: + if character[:2] == '\\u': + data = repr(c.decode(character, 'unicode-escape')) + data = data.strip("'") + color = discord.Color.green() + elif character[:2] == 'U+': + data = chr(int(character.lstrip('U+'), 16)) + color = discord.Color.green() + else: + data = '' + color = discord.Color.red() + except ValueError: + data = '' + color = discord.Color.red() + em = discord.Embed(title=character, description=data, color=color) + await self.bot.say(embed=em) + + +def setup(bot): + bot.add_cog(Unicode(bot))