From e1723f577943f24d855d093d005d0d8cca8a1d9c Mon Sep 17 00:00:00 2001 From: Bobloy Date: Mon, 14 May 2018 16:12:40 -0400 Subject: [PATCH] Snap-ons V3 conversion initial commit --- lovecalculator/__init__.py | 5 + lovecalculator/info.json | 23 ++++ lovecalculator/lovecalculator.py | 44 +++++++ recyclingplant/__init__.py | 9 ++ recyclingplant/data/junk.json | 204 +++++++++++++++++++++++++++++++ recyclingplant/info.json | 21 ++++ recyclingplant/recyclingplant.py | 67 ++++++++++ 7 files changed, 373 insertions(+) create mode 100644 lovecalculator/__init__.py create mode 100644 lovecalculator/info.json create mode 100644 lovecalculator/lovecalculator.py create mode 100644 recyclingplant/__init__.py create mode 100644 recyclingplant/data/junk.json create mode 100644 recyclingplant/info.json create mode 100644 recyclingplant/recyclingplant.py diff --git a/lovecalculator/__init__.py b/lovecalculator/__init__.py new file mode 100644 index 0000000..5284684 --- /dev/null +++ b/lovecalculator/__init__.py @@ -0,0 +1,5 @@ +from .lovecalculator import LoveCalculator + + +def setup(bot): + bot.add_cog(LoveCalculator(bot)) diff --git a/lovecalculator/info.json b/lovecalculator/info.json new file mode 100644 index 0000000..c0cb702 --- /dev/null +++ b/lovecalculator/info.json @@ -0,0 +1,23 @@ +{ + "author": [ + "Bobloy", + "SnappyDragon" + ], + "bot_version": [ + 3, + 0, + 0 + ], + "description": "Calculate the love percentage for two users", + "hidden": false, + "install_msg": "Thank you for installing LoveCalculator. Love is in the air.", + "requirements": [ + "beautifulsoup4" + ], + "short": "Calculate love percentage", + "tags": [ + "bobloy", + "fun", + "love" + ] +} \ No newline at end of file diff --git a/lovecalculator/lovecalculator.py b/lovecalculator/lovecalculator.py new file mode 100644 index 0000000..fc2ff8d --- /dev/null +++ b/lovecalculator/lovecalculator.py @@ -0,0 +1,44 @@ +import aiohttp +import discord +from bs4 import BeautifulSoup +from redbot.core import commands + + +class LoveCalculator: + """Calculate the love percentage for two users!""" + + def __init__(self, bot): + self.bot = bot + + @commands.command(aliases=['lovecalc']) + async def lovecalculator(self, ctx: commands.Context, lover: discord.Member, loved: discord.Member): + """Calculate the love percentage!""" + + x = lover.display_name + y = loved.display_name + + url = 'https://www.lovecalculator.com/love.php?name1={}&name2={}'.format(x.replace(" ", "+"), + y.replace(" ", "+")) + async with aiohttp.ClientSession() as session: + async with session.get(url) as response: + soup_object = BeautifulSoup(await response.text(), "html.parser") + try: + description = soup_object.find('div', attrs={'class': 'result score'}).get_text().strip() + except: + description = 'Dr. Love is busy right now' + + try: + z = description[:2] + z = int(z) + if z > 50: + emoji = '❤' + else: + emoji = '💔' + title = 'Dr. Love says that the love percentage for {} and {} is:'.format(x, y) + except: + emoji = '' + title = 'Dr. Love has left a note for you.' + + description = emoji + ' ' + description + ' ' + emoji + em = discord.Embed(title=title, description=description, color=discord.Color.red()) + await ctx.send(embed=em) diff --git a/recyclingplant/__init__.py b/recyclingplant/__init__.py new file mode 100644 index 0000000..e012d18 --- /dev/null +++ b/recyclingplant/__init__.py @@ -0,0 +1,9 @@ +from redbot.core import data_manager + +from .recyclingplant import RecyclingPlant + + +def setup(bot): + plant = RecyclingPlant(bot) + data_manager.load_bundled_data(plant, __file__) + bot.add_cog(plant) diff --git a/recyclingplant/data/junk.json b/recyclingplant/data/junk.json new file mode 100644 index 0000000..c77f881 --- /dev/null +++ b/recyclingplant/data/junk.json @@ -0,0 +1,204 @@ +{ + "can": [ + { + "object": "Apple Core", + "action": "trash" + }, + { + "object": "Paper Cup", + "action": "recycle" + }, + { + "object": "Banana Peel", + "action": "trash" + }, + { + "object": "Paper Bag", + "action": "recycle" + }, + { + "object": "Old Taco", + "action": "trash" + }, + { + "object": "Newspaper", + "action": "recycle" + }, + { + "object": "Chewed Gum", + "action": "trash" + }, + { + "object": "Polythene Bag", + "action": "recycle" + }, + { + "object": "Rotten Eggs", + "action": "trash" + }, + { + "object": "Outdated Telephone Directory", + "action": "recycle" + }, + { + "object": "Stale Bread", + "action": "trash" + }, + { + "object": "Used Notebook", + "action": "recycle" + }, + { + "object": "Sour Milk", + "action": "trash" + }, + { + "object": "Old Textbook", + "action": "recycle" + }, + { + "object": "Week-Old Sandwich", + "action": "trash" + }, + { + "object": "Paper Ball", + "action": "recycle" + }, + { + "object": "Leftovers", + "action": "trash" + }, + { + "object": "Toy Car", + "action": "recycle" + }, + { + "object": "Fish Bones", + "action": "trash" + }, + { + "object": "Superhero Costume", + "action": "recycle" + }, + { + "object": "Dirty Diaper", + "action": "trash" + }, + { + "object": "Silcone Mould", + "action": "recycle" + }, + { + "object": "Mouldy Broccoli", + "action": "trash" + }, + { + "object": "TV Remote", + "action": "recycle" + }, + { + "object": "Withered Rose Bouquet", + "action": "trash" + }, + { + "object": "Paper Plate", + "action": "recycle" + }, + { + "object": "Slimy Bacon", + "action": "trash" + }, + { + "object": "Folders", + "action": "recycle" + }, + { + "object": "Fly Agaric Mushrooms", + "action": "trash" + }, + { + "object": "Phone case", + "action": "recycle" + }, + { + "object": "Napkins", + "action": "trash" + }, + { + "object": "Broken Dualshock 4 Controller", + "action": "recycle" + }, + { + "object": "Wax Paper", + "action": "trash" + }, + { + "object": "iPad", + "action": "recycle" + }, + { + "object": "Paint Can", + "action": "trash" + }, + { + "object": "Glass Bottle", + "action": "recycle" + }, + { + "object": "Light Bulb", + "action": "trash" + }, + { + "object": "Nintendo 3DS", + "action": "recycle" + }, + { + "object": "Styrofoam Container", + "action": "trash" + }, + { + "object": "Flash Cards", + "action": "recycle" + }, + { + "object": "Motor Oil Can", + "action": "trash" + }, + { + "object": "Candy Wrapper", + "action": "recycle" + }, + { + "object": "Waxed Cardboard", + "action": "trash" + }, + { + "object": "Empty Bottle", + "action": "recycle" + }, + { + "object": "Used Toilet Paper", + "action": "trash" + }, + { + "object": "Outdated Calendar", + "action": "recycle" + }, + { + "object": "Ceramic Mug", + "action": "trash" + }, + { + "object": "Plastic Cup", + "action": "recycle" + }, + { + "object": "Gift Wrapping", + "action": "trash" + }, + { + "object": "Soda Bottle", + "action": "recycle" + } + ] +} diff --git a/recyclingplant/info.json b/recyclingplant/info.json new file mode 100644 index 0000000..62ac5df --- /dev/null +++ b/recyclingplant/info.json @@ -0,0 +1,21 @@ +{ + "author": [ + "Bobloy", + "SnappyDragon" + ], + "bot_version": [ + 3, + 0, + 0 + ], + "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!", + "requirements": [], + "short": "ply for a job at the recycling plant!", + "tags": [ + "bobloy", + "environment", + "games" + ] +} \ No newline at end of file diff --git a/recyclingplant/recyclingplant.py b/recyclingplant/recyclingplant.py new file mode 100644 index 0000000..b4c0d98 --- /dev/null +++ b/recyclingplant/recyclingplant.py @@ -0,0 +1,67 @@ +import asyncio +import json +import random + +from redbot.core import bank +from redbot.core import commands +from redbot.core.data_manager import cog_data_path + + +class RecyclingPlant: + """Apply for a job at the recycling plant!""" + + def __init__(self, bot): + self.bot = bot + self.path = str(cog_data_path(self)).replace('\\', '/') + self.junk_path = self.path + "/bundled_data/junk.json" + + with open(self.junk_path) as json_data: + self.junk = json.load(json_data) + + @commands.command() + async def recyclingplant(self, ctx: commands.Context): + """Apply for a job at the recycling plant!""" + x = 0 + reward = 0 + await ctx.send( + '{0} has signed up for a shift at the Recycling Plant! Type ``exit`` to terminate it early.'.format( + ctx.author.display_name)) + while x in range(0, 10): + used = random.choice(self.junk['can']) + if used['action'] == 'trash': + opp = 'recycle' + else: + opp = 'trash' + await ctx.send('``{}``! Will {} ``trash`` it or ``recycle`` it?'.format(used['object'], + ctx.author.display_name)) + + def check(m): + return m.author == ctx.author and m.channel == ctx.channel + + try: + answer = await self.bot.wait_for('message', timeout=120, check=check) + except asyncio.TimeoutError: + answer = None + + if answer is None: + await ctx.send('``{}`` fell down the conveyor belt to be sorted again!'.format(used['object'])) + elif answer.content.lower().strip() == used['action']: + await ctx.send( + 'Congratulations! You put ``{}`` down the correct chute! (**+50**)'.format(used['object'])) + reward = reward + 50 + x += 1 + elif answer.content.lower().strip() == opp: + await ctx.send('{}, you little brute, you put it down the wrong chute! (**-50**)'.format( + ctx.author.display_name)) + reward = reward - 50 + elif answer.content.lower().strip() == 'exit': + await ctx.send('{} has been relived of their duty.'.format(ctx.author.display_name)) + break + else: + await ctx.send('``{}`` fell down the conveyor belt to be sorted again!'.format(used['object'])) + else: + if reward > 0: + bank.deposit_credits(ctx.author, reward) + await ctx.send( + '{} been given **{} {}s** for your services.'.format(ctx.author.display_name, reward, + bank.get_currency_name(ctx.guild)))