aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/halloween
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2020-09-24 18:54:39 +0300
committerGravatar ks129 <[email protected]>2020-09-24 18:54:39 +0300
commita3246bd40a3a496ad155d02653d3104392d9ff8e (patch)
treefffc704f2cc09c44f4727872d8ad80bad5a10ae9 /bot/exts/halloween
parentTictactoe: Use __str__ instead custom display method for user/AI name display (diff)
parentMerge branch 'master' into tic-tac-toe (diff)
Merge remote-tracking branch 'origin/tic-tac-toe' into tic-tac-toe
Diffstat (limited to 'bot/exts/halloween')
-rw-r--r--bot/exts/halloween/candy_collection.py10
-rw-r--r--bot/exts/halloween/hacktoberstats.py4
-rw-r--r--bot/exts/halloween/halloween_facts.py2
-rw-r--r--bot/exts/halloween/halloweenify.py21
-rw-r--r--bot/exts/halloween/monstersurvey.py4
-rw-r--r--bot/exts/halloween/spookyrating.py2
-rw-r--r--bot/exts/halloween/spookysound.py7
7 files changed, 33 insertions, 17 deletions
diff --git a/bot/exts/halloween/candy_collection.py b/bot/exts/halloween/candy_collection.py
index 90c29eb2..caf0df11 100644
--- a/bot/exts/halloween/candy_collection.py
+++ b/bot/exts/halloween/candy_collection.py
@@ -27,7 +27,7 @@ class CandyCollection(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
- with open(json_location) as candy:
+ with open(json_location, encoding="utf8") as candy:
self.candy_json = json.load(candy)
self.msg_reacted = self.candy_json['msg_reacted']
self.get_candyinfo = dict()
@@ -178,7 +178,7 @@ class CandyCollection(commands.Cog):
def save_to_json(self) -> None:
"""Save JSON to a local file."""
- with open(json_location, 'w') as outfile:
+ with open(json_location, 'w', encoding="utf8") as outfile:
json.dump(self.candy_json, outfile)
@in_month(Month.OCTOBER)
@@ -212,9 +212,9 @@ class CandyCollection(commands.Cog):
e = discord.Embed(colour=discord.Colour.blurple())
e.add_field(name="Top Candy Records", value=value, inline=False)
e.add_field(name='\u200b',
- value=f"Candies will randomly appear on messages sent. "
- f"\nHit the candy when it appears as fast as possible to get the candy! "
- f"\nBut beware the ghosts...",
+ value="Candies will randomly appear on messages sent. "
+ "\nHit the candy when it appears as fast as possible to get the candy! "
+ "\nBut beware the ghosts...",
inline=False)
await ctx.send(embed=e)
diff --git a/bot/exts/halloween/hacktoberstats.py b/bot/exts/halloween/hacktoberstats.py
index e01ee50c..db5e37f2 100644
--- a/bot/exts/halloween/hacktoberstats.py
+++ b/bot/exts/halloween/hacktoberstats.py
@@ -123,7 +123,7 @@ class HacktoberStats(commands.Cog):
"""
if self.link_json.exists():
logging.info(f"Loading linked GitHub accounts from '{self.link_json}'")
- with open(self.link_json, 'r') as file:
+ with open(self.link_json, 'r', encoding="utf8") as file:
linked_accounts = json.load(file)
logging.info(f"Loaded {len(linked_accounts)} linked GitHub accounts from '{self.link_json}'")
@@ -145,7 +145,7 @@ class HacktoberStats(commands.Cog):
}
"""
logging.info(f"Saving linked_accounts to '{self.link_json}'")
- with open(self.link_json, 'w') as file:
+ with open(self.link_json, 'w', encoding="utf8") as file:
json.dump(self.linked_accounts, file, default=str)
logging.info(f"linked_accounts saved to '{self.link_json}'")
diff --git a/bot/exts/halloween/halloween_facts.py b/bot/exts/halloween/halloween_facts.py
index 44a66ab2..7eb6d56f 100644
--- a/bot/exts/halloween/halloween_facts.py
+++ b/bot/exts/halloween/halloween_facts.py
@@ -29,7 +29,7 @@ class HalloweenFacts(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
- with open(Path("bot/resources/halloween/halloween_facts.json"), "r") as file:
+ with open(Path("bot/resources/halloween/halloween_facts.json"), "r", encoding="utf8") as file:
self.halloween_facts = json.load(file)
self.facts = list(enumerate(self.halloween_facts))
random.shuffle(self.facts)
diff --git a/bot/exts/halloween/halloweenify.py b/bot/exts/halloween/halloweenify.py
index 5c433a81..596c6682 100644
--- a/bot/exts/halloween/halloweenify.py
+++ b/bot/exts/halloween/halloweenify.py
@@ -4,6 +4,7 @@ from pathlib import Path
from random import choice
import discord
+from discord.errors import Forbidden
from discord.ext import commands
from discord.ext.commands.cooldowns import BucketType
@@ -21,7 +22,7 @@ class Halloweenify(commands.Cog):
async def halloweenify(self, ctx: commands.Context) -> None:
"""Change your nickname into a much spookier one!"""
async with ctx.typing():
- with open(Path("bot/resources/halloween/halloweenify.json"), "r") as f:
+ with open(Path("bot/resources/halloween/halloweenify.json"), "r", encoding="utf8") as f:
data = load(f)
# Choose a random character from our list we loaded above and set apart the nickname and image url.
@@ -37,11 +38,25 @@ class Halloweenify(commands.Cog):
f"**{ctx.author.display_name}** wasn\'t spooky enough for you? That\'s understandable, "
f"{ctx.author.display_name} isn\'t scary at all! "
"Let me think of something better. Hmm... I got it!\n\n "
- f"Your new nickname will be: \n :ghost: **{nickname}** :jack_o_lantern:"
)
embed.set_image(url=image)
- await ctx.author.edit(nick=nickname)
+ if isinstance(ctx.author, discord.Member):
+ try:
+ await ctx.author.edit(nick=nickname)
+ embed.description += f"Your new nickname will be: \n:ghost: **{nickname}** :jack_o_lantern:"
+
+ except Forbidden: # The bot doesn't have enough permission
+ embed.description += (
+ f"Your new nickname should be: \n :ghost: **{nickname}** :jack_o_lantern: \n\n"
+ f"It looks like I cannot change your name, but feel free to change it yourself."
+ )
+
+ else: # The command has been invoked in DM
+ embed.description += (
+ f"Your new nickname should be: \n :ghost: **{nickname}** :jack_o_lantern: \n\n"
+ f"Feel free to change it yourself, or invoke the command again inside the server."
+ )
await ctx.send(embed=embed)
diff --git a/bot/exts/halloween/monstersurvey.py b/bot/exts/halloween/monstersurvey.py
index 27da79b6..7b1a1e84 100644
--- a/bot/exts/halloween/monstersurvey.py
+++ b/bot/exts/halloween/monstersurvey.py
@@ -27,13 +27,13 @@ class MonsterSurvey(Cog):
"""Initializes values for the bot to use within the voting commands."""
self.bot = bot
self.registry_location = os.path.join(os.getcwd(), 'bot', 'resources', 'halloween', 'monstersurvey.json')
- with open(self.registry_location, 'r') as jason:
+ with open(self.registry_location, 'r', encoding="utf8") as jason:
self.voter_registry = json.load(jason)
def json_write(self) -> None:
"""Write voting results to a local JSON file."""
log.info("Saved Monster Survey Results")
- with open(self.registry_location, 'w') as jason:
+ with open(self.registry_location, 'w', encoding="utf8") as jason:
json.dump(self.voter_registry, jason, indent=2)
def cast_vote(self, id: int, monster: str) -> None:
diff --git a/bot/exts/halloween/spookyrating.py b/bot/exts/halloween/spookyrating.py
index 1a48194e..6f069f8c 100644
--- a/bot/exts/halloween/spookyrating.py
+++ b/bot/exts/halloween/spookyrating.py
@@ -11,7 +11,7 @@ from bot.constants import Colours
log = logging.getLogger(__name__)
-with Path("bot/resources/halloween/spooky_rating.json").open() as file:
+with Path("bot/resources/halloween/spooky_rating.json").open(encoding="utf8") as file:
SPOOKY_DATA = json.load(file)
SPOOKY_DATA = sorted((int(key), value) for key, value in SPOOKY_DATA.items())
diff --git a/bot/exts/halloween/spookysound.py b/bot/exts/halloween/spookysound.py
index 325447e5..569a9153 100644
--- a/bot/exts/halloween/spookysound.py
+++ b/bot/exts/halloween/spookysound.py
@@ -5,6 +5,7 @@ from pathlib import Path
import discord
from discord.ext import commands
+from bot.bot import SeasonalBot
from bot.constants import Hacktoberfest
log = logging.getLogger(__name__)
@@ -13,7 +14,7 @@ log = logging.getLogger(__name__)
class SpookySound(commands.Cog):
"""A cog that plays a spooky sound in a voice channel on command."""
- def __init__(self, bot: commands.Bot):
+ def __init__(self, bot: SeasonalBot):
self.bot = bot
self.sound_files = list(Path("bot/resources/halloween/spookysounds").glob("*.mp3"))
self.channel = None
@@ -27,7 +28,7 @@ class SpookySound(commands.Cog):
Cannot be used more than once in 2 minutes.
"""
if not self.channel:
- await self.bot.wait_until_ready()
+ await self.bot.wait_until_guild_available()
self.channel = self.bot.get_channel(Hacktoberfest.voice_id)
await ctx.send("Initiating spooky sound...")
@@ -42,6 +43,6 @@ class SpookySound(commands.Cog):
await voice.disconnect()
-def setup(bot: commands.Bot) -> None:
+def setup(bot: SeasonalBot) -> None:
"""Spooky sound Cog load."""
bot.add_cog(SpookySound(bot))