From 0e0f5ca437176cec90db7203fb49004b78de4acc Mon Sep 17 00:00:00 2001 From: Suhail Date: Thu, 14 Mar 2019 21:37:35 +0000 Subject: Spooky Rating Added the cog containing the spookyrating command and added the JSON file containing all the ratings --- bot/resources/halloween/spooky_rating.json | 47 ++++++++++++++++++ bot/seasons/halloween/spookyrating.py | 77 ++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 bot/resources/halloween/spooky_rating.json create mode 100644 bot/seasons/halloween/spookyrating.py (limited to 'bot') diff --git a/bot/resources/halloween/spooky_rating.json b/bot/resources/halloween/spooky_rating.json new file mode 100644 index 00000000..2c459926 --- /dev/null +++ b/bot/resources/halloween/spooky_rating.json @@ -0,0 +1,47 @@ +{ + "0": { + "title": "\uD83D\uDD6F You're not scarin' anyone \uD83D\uDD6F", + "text": "No matter what you say or do, nobody even flinches when you try to scare them. Was your costume this year only a white sheet with holes for eyes? Or did you even bother with a costume at all? Either way, don't expect too many treats when going from door-to-door.", + "image": "https://www.thoughtco.com/thmb/qv6FUFM6V_p7YUAk9lT6fZG8s3M=/768x0/filters:no_upscale():max_bytes(150000):strip_icc()/smoke-trailing-from-extinguished-white-candle-565954737-584daec23df78c491e6282a5.jpg" + }, + "5": { + "title": "\uD83D\uDC76 Like taking candy from a baby \uD83D\uDC76", + "text": "Your scaring will probably make a baby cry... but that's the limit on your frightening powers. Be careful not to get to the point where everyone's running away from you because they don't like you, not because they're scared of you.", + "image": "https://static3.babygagaimages.com/wordpress/wp-content/uploads/2017/01/78ibcx9ire.jpg" + }, + "20": { + "title": "\uD83C\uDFDA You're skills are forming... \uD83C\uDFDA", + "text": "As you become the Devil's apprentice, you begin to make people jump every time you sneak up on them. A good start, but you have to learn not to wear the same costume every year until it doesn't fit you. People will notice you and your prowess will decrease.", + "image": "https://www.kimballstock.com/pix/TGR/04/TGR-04-AC0011-01P.JPG" + }, + "30": { + "title": "\uD83D\uDC80 Picture Perfect... \uD83D\uDC80", + "text": "You've nailed the costume this year! You look suuuper scary! Now make sure to play the part and act out your costume and you'll be sure to give a few people a massive fright!", + "image": "https://inst-2.cdn.shockers.de/hs_cdn/out/pictures//master/product/1/3d-skelett-kostuem-adult--skelett-overall-fuer-halloween--skeleton-jumpsuit-costume--15555.jpg" + }, + "50": { + "title": "\uD83D\uDC7B Uhm... are you human \uD83D\uDC7B", + "text": "Uhm... you're too good to be human and now you're beginning to sound like a ghost. You're almost invisible when haunting and nobody truly knows where you are at any given time. But they will always scream at the sound of a ghost...", + "image": "https://d2v9y0dukr6mq2.cloudfront.net/video/thumbnail/B3mqp6o/videoblocks-shadow-silhouette-of-a-dark-halloween-ghost-dancing-in-fog-behind-the-glass_sfmu3or_g_thumbnail-full01.png" + }, + "65": { + "title": "\uD83C\uDF83 That potion can't be real \uD83C\uDF83", + "text": "You're carrying... some... unknown liquids and no one knows who they are but yourself. Be careful on who you use these powerful spells on, because no Mage has the power to do any irreversible enchantments because even you won't know what will happen to these mortals.", + "image": "https://gswiki.play.net/images/thumb/7/7e/Necromancer.jpg/450px-Necromancer.jpg" + }, + "80": { + "title": "\uD83E\uDD21 The most sinister face \uD83E\uDD21", + "text": "Who knew something intended to be playful could be so menacing... Especially other people seeing you in their nightmares, continuing to haunt them day by day, stuck in their head throughout the entire year. Make sure to pull a face they will never forget.", + "image": "https://www.indiewire.com/wp-content/uploads/2018/07/pennywise-bill-skarsgard-it-movie.jpg?w=780" + }, + "95": { + "title": "\uD83D\uDE08 The Devil's Accomplice \uD83D\uDE08", + "text": "Imagine being allies with the most evil character with an aim to scare people to death. Force people to suffer as they proceed straight to hell to meet your boss and best friend. Not even you know the power He has...", + "image": "https://d2gg9evh47fn9z.cloudfront.net/800px_COLOURBOX6978186.jpg" + }, + "100": { + "title":"\uD83D\uDC7F The Devil Himself \uD83D\uDC7F", + "text": "You are the evillest creature in existence to scare anyone and everyone humanly possible. The reason your underlings are called mortals is that they die. With your help, they die a lot quicker. With all the evil power in the universe, you know what to do.", + "image": "https://images.drawinghub.com/13941_501/how-to-draw-a-devil-face_5afe20070a9c10.00090710_10491_3_4.png" + } +} \ No newline at end of file diff --git a/bot/seasons/halloween/spookyrating.py b/bot/seasons/halloween/spookyrating.py new file mode 100644 index 00000000..92f71b9e --- /dev/null +++ b/bot/seasons/halloween/spookyrating.py @@ -0,0 +1,77 @@ +import bisect +import json +import logging +import random +from pathlib import Path + +import discord +from discord.ext import commands + +from bot.constants import Colours + +log = logging.getLogger(__name__) + +with Path('bot', 'resources', 'halloween', 'spooky_rating.json').open() as file: + SPOOKY_DATA = json.load(file) + SPOOKY_DATA = sorted((int(key), value) for key, value in SPOOKY_DATA.items()) + + +class SpookyRating: + """ + A cog for calculating one's spooky rating + """ + + def __init__(self, bot): + self.bot = bot + + @commands.command() + @commands.cooldown(rate=1, per=5, type=commands.BucketType.user) + async def spookyrating(self, ctx, who: discord.Member = None): + """ + Calculates the spooky rating of someone. + + This command accepts an optional user as an argument, defaulting to the command executor. + Users are converted from: + - User ID + - Mention + - name#discrim + - name + - nickname + + Any user will always yield the same result, no matter who calls the command + """ + + if who is None: + who = ctx.author + + # This ensures that the same result over multiple runtimes + random.seed(who.id) + + spooky_percent = random.randint(1, 100) + + # We need the -1 due to how bisect returns the point + # see the documentation for further detail + # https://docs.python.org/3/library/bisect.html#bisect.bisect + index = bisect.bisect(SPOOKY_DATA, (spooky_percent,)) - 1 + + _, data = SPOOKY_DATA[index] + + embed = discord.Embed( + title=data['title'], + description=f'{who} scored {spooky_percent}%!', + color=Colours.orange + ) + embed.add_field( + name='A whisper from Satan', + value=data['text'] + ) + embed.set_thumbnail( + url=data['image'] + ) + + await ctx.send(embed=embed) + + +def setup(bot): + bot.add_cog(SpookyRating(bot)) + log.info("SpookyRating cog loaded") -- cgit v1.2.3 From 722ed131b59982caf8e54ca8bfbc36989ec2aae4 Mon Sep 17 00:00:00 2001 From: Suhail Date: Tue, 19 Mar 2019 23:09:42 +0000 Subject: Spooky Rating - Fixed Requested Changes - Removed the documentation on how Users are converted - Changed random to a local state rather than using global seed - Changed the JSON minimum to -1 due to how bisect works --- bot/resources/halloween/spooky_rating.json | 2 +- bot/seasons/halloween/spookyrating.py | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) (limited to 'bot') diff --git a/bot/resources/halloween/spooky_rating.json b/bot/resources/halloween/spooky_rating.json index 2c459926..b83624fe 100644 --- a/bot/resources/halloween/spooky_rating.json +++ b/bot/resources/halloween/spooky_rating.json @@ -1,5 +1,5 @@ { - "0": { + "-1": { "title": "\uD83D\uDD6F You're not scarin' anyone \uD83D\uDD6F", "text": "No matter what you say or do, nobody even flinches when you try to scare them. Was your costume this year only a white sheet with holes for eyes? Or did you even bother with a costume at all? Either way, don't expect too many treats when going from door-to-door.", "image": "https://www.thoughtco.com/thmb/qv6FUFM6V_p7YUAk9lT6fZG8s3M=/768x0/filters:no_upscale():max_bytes(150000):strip_icc()/smoke-trailing-from-extinguished-white-candle-565954737-584daec23df78c491e6282a5.jpg" diff --git a/bot/seasons/halloween/spookyrating.py b/bot/seasons/halloween/spookyrating.py index 92f71b9e..8c4f1b12 100644 --- a/bot/seasons/halloween/spookyrating.py +++ b/bot/seasons/halloween/spookyrating.py @@ -23,6 +23,7 @@ class SpookyRating: def __init__(self, bot): self.bot = bot + self.local_random = random.Random() @commands.command() @commands.cooldown(rate=1, per=5, type=commands.BucketType.user) @@ -30,14 +31,6 @@ class SpookyRating: """ Calculates the spooky rating of someone. - This command accepts an optional user as an argument, defaulting to the command executor. - Users are converted from: - - User ID - - Mention - - name#discrim - - name - - nickname - Any user will always yield the same result, no matter who calls the command """ @@ -45,9 +38,8 @@ class SpookyRating: who = ctx.author # This ensures that the same result over multiple runtimes - random.seed(who.id) - - spooky_percent = random.randint(1, 100) + self.local_random.seed(who.id) + spooky_percent = self.local_random.randint(1, 101) # We need the -1 due to how bisect returns the point # see the documentation for further detail -- cgit v1.2.3 From f0b2a978b67a6277459e580626aba02a479ba713 Mon Sep 17 00:00:00 2001 From: Suhail Date: Sun, 31 Mar 2019 14:07:03 +0100 Subject: Fixed Images to Public Use images Added them to the repo and linked to the raw --- bot/resources/halloween/spooky_rating.json | 18 +++++++++--------- bot/resources/halloween/spookyrating/baby.jpeg | Bin 0 -> 110346 bytes bot/resources/halloween/spookyrating/candle.jpeg | Bin 0 -> 45981 bytes bot/resources/halloween/spookyrating/clown.jpeg | Bin 0 -> 53035 bytes bot/resources/halloween/spookyrating/costume.jpeg | Bin 0 -> 88629 bytes bot/resources/halloween/spookyrating/devil.jpeg | Bin 0 -> 336208 bytes bot/resources/halloween/spookyrating/ghost.jpeg | Bin 0 -> 29635 bytes .../halloween/spookyrating/jackolantern.jpeg | Bin 0 -> 17598 bytes bot/resources/halloween/spookyrating/necromancer.jpeg | Bin 0 -> 139672 bytes bot/resources/halloween/spookyrating/tiger.jpeg | Bin 0 -> 52851 bytes 10 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 bot/resources/halloween/spookyrating/baby.jpeg create mode 100644 bot/resources/halloween/spookyrating/candle.jpeg create mode 100644 bot/resources/halloween/spookyrating/clown.jpeg create mode 100644 bot/resources/halloween/spookyrating/costume.jpeg create mode 100644 bot/resources/halloween/spookyrating/devil.jpeg create mode 100644 bot/resources/halloween/spookyrating/ghost.jpeg create mode 100644 bot/resources/halloween/spookyrating/jackolantern.jpeg create mode 100644 bot/resources/halloween/spookyrating/necromancer.jpeg create mode 100644 bot/resources/halloween/spookyrating/tiger.jpeg (limited to 'bot') diff --git a/bot/resources/halloween/spooky_rating.json b/bot/resources/halloween/spooky_rating.json index b83624fe..1815befc 100644 --- a/bot/resources/halloween/spooky_rating.json +++ b/bot/resources/halloween/spooky_rating.json @@ -2,46 +2,46 @@ "-1": { "title": "\uD83D\uDD6F You're not scarin' anyone \uD83D\uDD6F", "text": "No matter what you say or do, nobody even flinches when you try to scare them. Was your costume this year only a white sheet with holes for eyes? Or did you even bother with a costume at all? Either way, don't expect too many treats when going from door-to-door.", - "image": "https://www.thoughtco.com/thmb/qv6FUFM6V_p7YUAk9lT6fZG8s3M=/768x0/filters:no_upscale():max_bytes(150000):strip_icc()/smoke-trailing-from-extinguished-white-candle-565954737-584daec23df78c491e6282a5.jpg" + "image": "https://raw.githubusercontent.com/python-discord/seasonalbot/master/bot/resources/halloween/spookyrating/candle.jpeg" }, "5": { "title": "\uD83D\uDC76 Like taking candy from a baby \uD83D\uDC76", "text": "Your scaring will probably make a baby cry... but that's the limit on your frightening powers. Be careful not to get to the point where everyone's running away from you because they don't like you, not because they're scared of you.", - "image": "https://static3.babygagaimages.com/wordpress/wp-content/uploads/2017/01/78ibcx9ire.jpg" + "image": "https://raw.githubusercontent.com/python-discord/seasonalbot/master/bot/resources/halloween/spookyrating/baby.jpeg" }, "20": { "title": "\uD83C\uDFDA You're skills are forming... \uD83C\uDFDA", "text": "As you become the Devil's apprentice, you begin to make people jump every time you sneak up on them. A good start, but you have to learn not to wear the same costume every year until it doesn't fit you. People will notice you and your prowess will decrease.", - "image": "https://www.kimballstock.com/pix/TGR/04/TGR-04-AC0011-01P.JPG" + "image": "https://raw.githubusercontent.com/python-discord/seasonalbot/master/bot/resources/halloween/spookyrating/tiger.jpeg" }, "30": { "title": "\uD83D\uDC80 Picture Perfect... \uD83D\uDC80", "text": "You've nailed the costume this year! You look suuuper scary! Now make sure to play the part and act out your costume and you'll be sure to give a few people a massive fright!", - "image": "https://inst-2.cdn.shockers.de/hs_cdn/out/pictures//master/product/1/3d-skelett-kostuem-adult--skelett-overall-fuer-halloween--skeleton-jumpsuit-costume--15555.jpg" + "image": "https://raw.githubusercontent.com/python-discord/seasonalbot/master/bot/resources/halloween/spookyrating/costume.jpeg" }, "50": { "title": "\uD83D\uDC7B Uhm... are you human \uD83D\uDC7B", "text": "Uhm... you're too good to be human and now you're beginning to sound like a ghost. You're almost invisible when haunting and nobody truly knows where you are at any given time. But they will always scream at the sound of a ghost...", - "image": "https://d2v9y0dukr6mq2.cloudfront.net/video/thumbnail/B3mqp6o/videoblocks-shadow-silhouette-of-a-dark-halloween-ghost-dancing-in-fog-behind-the-glass_sfmu3or_g_thumbnail-full01.png" + "image": "https://raw.githubusercontent.com/python-discord/seasonalbot/master/bot/resources/halloween/spookyrating/ghost.jpeg" }, "65": { "title": "\uD83C\uDF83 That potion can't be real \uD83C\uDF83", "text": "You're carrying... some... unknown liquids and no one knows who they are but yourself. Be careful on who you use these powerful spells on, because no Mage has the power to do any irreversible enchantments because even you won't know what will happen to these mortals.", - "image": "https://gswiki.play.net/images/thumb/7/7e/Necromancer.jpg/450px-Necromancer.jpg" + "image": "https://raw.githubusercontent.com/python-discord/seasonalbot/master/bot/resources/halloween/spookyrating/necromancer.jepg" }, "80": { "title": "\uD83E\uDD21 The most sinister face \uD83E\uDD21", "text": "Who knew something intended to be playful could be so menacing... Especially other people seeing you in their nightmares, continuing to haunt them day by day, stuck in their head throughout the entire year. Make sure to pull a face they will never forget.", - "image": "https://www.indiewire.com/wp-content/uploads/2018/07/pennywise-bill-skarsgard-it-movie.jpg?w=780" + "image": "https://raw.githubusercontent.com/python-discord/seasonalbot/master/bot/resources/halloween/spookyrating/clown.jpeg" }, "95": { "title": "\uD83D\uDE08 The Devil's Accomplice \uD83D\uDE08", "text": "Imagine being allies with the most evil character with an aim to scare people to death. Force people to suffer as they proceed straight to hell to meet your boss and best friend. Not even you know the power He has...", - "image": "https://d2gg9evh47fn9z.cloudfront.net/800px_COLOURBOX6978186.jpg" + "image": "https://raw.githubusercontent.com/python-discord/seasonalbot/master/bot/resources/halloween/spookyrating/jackolantern.jpg" }, "100": { "title":"\uD83D\uDC7F The Devil Himself \uD83D\uDC7F", "text": "You are the evillest creature in existence to scare anyone and everyone humanly possible. The reason your underlings are called mortals is that they die. With your help, they die a lot quicker. With all the evil power in the universe, you know what to do.", - "image": "https://images.drawinghub.com/13941_501/how-to-draw-a-devil-face_5afe20070a9c10.00090710_10491_3_4.png" + "image": "https://raw.githubusercontent.com/python-discord/seasonalbot/master/bot/resources/halloween/spookyrating/devil.jpeg" } } \ No newline at end of file diff --git a/bot/resources/halloween/spookyrating/baby.jpeg b/bot/resources/halloween/spookyrating/baby.jpeg new file mode 100644 index 00000000..199f8bca Binary files /dev/null and b/bot/resources/halloween/spookyrating/baby.jpeg differ diff --git a/bot/resources/halloween/spookyrating/candle.jpeg b/bot/resources/halloween/spookyrating/candle.jpeg new file mode 100644 index 00000000..9913752b Binary files /dev/null and b/bot/resources/halloween/spookyrating/candle.jpeg differ diff --git a/bot/resources/halloween/spookyrating/clown.jpeg b/bot/resources/halloween/spookyrating/clown.jpeg new file mode 100644 index 00000000..f23c4f70 Binary files /dev/null and b/bot/resources/halloween/spookyrating/clown.jpeg differ diff --git a/bot/resources/halloween/spookyrating/costume.jpeg b/bot/resources/halloween/spookyrating/costume.jpeg new file mode 100644 index 00000000..b3c21af0 Binary files /dev/null and b/bot/resources/halloween/spookyrating/costume.jpeg differ diff --git a/bot/resources/halloween/spookyrating/devil.jpeg b/bot/resources/halloween/spookyrating/devil.jpeg new file mode 100644 index 00000000..4f45aaa7 Binary files /dev/null and b/bot/resources/halloween/spookyrating/devil.jpeg differ diff --git a/bot/resources/halloween/spookyrating/ghost.jpeg b/bot/resources/halloween/spookyrating/ghost.jpeg new file mode 100644 index 00000000..0cb13346 Binary files /dev/null and b/bot/resources/halloween/spookyrating/ghost.jpeg differ diff --git a/bot/resources/halloween/spookyrating/jackolantern.jpeg b/bot/resources/halloween/spookyrating/jackolantern.jpeg new file mode 100644 index 00000000..d7cf3d08 Binary files /dev/null and b/bot/resources/halloween/spookyrating/jackolantern.jpeg differ diff --git a/bot/resources/halloween/spookyrating/necromancer.jpeg b/bot/resources/halloween/spookyrating/necromancer.jpeg new file mode 100644 index 00000000..60b1e689 Binary files /dev/null and b/bot/resources/halloween/spookyrating/necromancer.jpeg differ diff --git a/bot/resources/halloween/spookyrating/tiger.jpeg b/bot/resources/halloween/spookyrating/tiger.jpeg new file mode 100644 index 00000000..0419f5df Binary files /dev/null and b/bot/resources/halloween/spookyrating/tiger.jpeg differ -- cgit v1.2.3 From 6b044e8e8a596d10b9284a1c14fb549ec19b02cd Mon Sep 17 00:00:00 2001 From: Suhail Date: Sun, 31 Mar 2019 14:14:49 +0100 Subject: Docstring Fixes --- bot/seasons/halloween/spookyrating.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'bot') diff --git a/bot/seasons/halloween/spookyrating.py b/bot/seasons/halloween/spookyrating.py index 8c4f1b12..01fb607b 100644 --- a/bot/seasons/halloween/spookyrating.py +++ b/bot/seasons/halloween/spookyrating.py @@ -17,9 +17,7 @@ with Path('bot', 'resources', 'halloween', 'spooky_rating.json').open() as file: class SpookyRating: - """ - A cog for calculating one's spooky rating - """ + """A cog for calculating one's spooky rating""" def __init__(self, bot): self.bot = bot @@ -65,5 +63,6 @@ class SpookyRating: def setup(bot): + """Cog load.""" bot.add_cog(SpookyRating(bot)) log.info("SpookyRating cog loaded") -- cgit v1.2.3 From 7306ca0fb508c5192c47ac5db02ca998f443fc77 Mon Sep 17 00:00:00 2001 From: Suhail Date: Sun, 31 Mar 2019 14:52:30 +0100 Subject: add `commands.Cog` --- bot/seasons/halloween/spookyrating.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/halloween/spookyrating.py b/bot/seasons/halloween/spookyrating.py index 01fb607b..a9cfda9b 100644 --- a/bot/seasons/halloween/spookyrating.py +++ b/bot/seasons/halloween/spookyrating.py @@ -16,7 +16,7 @@ with Path('bot', 'resources', 'halloween', 'spooky_rating.json').open() as file: SPOOKY_DATA = sorted((int(key), value) for key, value in SPOOKY_DATA.items()) -class SpookyRating: +class SpookyRating(commands.Cog): """A cog for calculating one's spooky rating""" def __init__(self, bot): -- cgit v1.2.3