aboutsummaryrefslogtreecommitdiff
path: root/cogs
diff options
context:
space:
mode:
authorMango0x45 <thomasvoss@live.com>2021-01-04 00:10:21 +0000
committerMango0x45 <thomasvoss@live.com>2021-01-04 00:10:21 +0000
commitb27570db9eb993bc74e47eab168f55a071b62870 (patch)
treee00fe961bb8c44e0537d5ca0cf6b8d7c1aa6dce2 /cogs
parentb324ac424dd1e31654c14b832fb791119c1934eb (diff)
downloadsteve-bot-b27570db9eb993bc74e47eab168f55a071b62870.tar
steve-bot-b27570db9eb993bc74e47eab168f55a071b62870.tar.gz
steve-bot-b27570db9eb993bc74e47eab168f55a071b62870.tar.bz2
steve-bot-b27570db9eb993bc74e47eab168f55a071b62870.tar.lz
steve-bot-b27570db9eb993bc74e47eab168f55a071b62870.tar.xz
steve-bot-b27570db9eb993bc74e47eab168f55a071b62870.tar.zst
steve-bot-b27570db9eb993bc74e47eab168f55a071b62870.zip
Removed walrus (rip 3.8 on debian)
Diffstat (limited to 'cogs')
-rwxr-xr-xcogs/utils.py85
1 files changed, 51 insertions, 34 deletions
diff --git a/cogs/utils.py b/cogs/utils.py
index 67a29ee..fdc7a9f 100755
--- a/cogs/utils.py
+++ b/cogs/utils.py
@@ -5,13 +5,13 @@ import json
import subprocess
from collections import namedtuple
from datetime import timedelta
-from pytz import timezone, exceptions
# forgot to import this and ended up looking mentally unstable
# troll literally pointed out atleast 4 things I did wrong in 3 lines of code
from random import choice, randint
import discord
from discord.ext import commands, tasks
+from pytz import exceptions, timezone
# from PIL.Image import core as Image
# import image as Image
@@ -387,16 +387,19 @@ class Utils(commands.Cog):
with open("fair.json", "r") as f:
fair = json.load(f)
-
# if fairer's ID in fair.json
- if (userId := str(message.author.id)) in fair:
+ userId = str(message.author.id)
+ if userId in fair:
# TODO: use timezones (get this time based on timezones to fair.json - default to GMT)
tz = fair[userId]["timezone"]
today = str(datetime.datetime.now(timezone(tz)).date())
- yesterday = str(datetime.datetime.now(timezone(tz)).date() - timedelta(1))
+ yesterday = str(
+ datetime.datetime.now(timezone(tz)).date() - timedelta(1)
+ )
# if date in json != current date
- if (date := fair[userId]["date"]) != today:
+ date = fair[userId]["date"]
+ if date != today:
# increment fair day
fairDay = fair[userId]["day"] + 1
@@ -409,24 +412,36 @@ class Utils(commands.Cog):
await message.channel.send("streak lost. :sad:")
# only send && update if user is fairing for the first time today
- fair[userId] = {"day": fairDay, "streak": fairStreak, "date": today, "timezone": tz}
+ fair[userId] = {
+ "day": fairDay,
+ "streak": fairStreak,
+ "date": today,
+ "timezone": tz,
+ }
fairInfo = f"day {fair[userId]['day']}, streak {fair[userId]['streak']}"
await message.channel.send(fairInfo)
-
+
# new user - not in fair.json
else:
# default to GMT
tz = "Europe/London"
today = str(datetime.datetime.now(timezone(tz)).date())
- fair[userId] = {"day": 1, "streak": 1, "date": today, "timezone": tz}
-
- fairInfo = f"day {fair[userId]['day']}, streak {fair[userId]['streak']}"
+ fair[userId] = {
+ "day": 1,
+ "streak": 1,
+ "date": today,
+ "timezone": tz,
+ }
+
+ fairInfo = (
+ f"day {fair[userId]['day']}, streak {fair[userId]['streak']}"
+ )
await message.channel.send(fairInfo)
# overwrite with new fair object
with open("fair.json", "w") as f:
- json.dump(fair, f, indent = 4)
+ json.dump(fair, f, indent=4)
count += 1
fairMsg = "Fair " * count
@@ -434,7 +449,6 @@ class Utils(commands.Cog):
await message.channel.send(fairMsg)
except UnboundLocalError:
pass
-
# 4 minute cooldown
# should probably be longer - we can't have these kids cheating!
@@ -448,18 +462,21 @@ class Utils(commands.Cog):
fair = json.load(f)
# if this user has faired before
- if (userId := str(ctx.author.id)) not in fair:
+ userId = str(ctx.author.id)
+ if userId not in fair:
# new user
await ctx.send("try saying 'fair' first")
return
-
+
try:
# let users timezone = input timezone (string version so as to please json)
# use timezone() simply to see if it's valid
- tz = str(timezone(timeZone))
+ tz = str(timezone(timeZone))
except exceptions.UnknownTimeZoneError:
- await ctx.send("That's not a valid timezone. You can look them up at https://kevinnovak.github.io/Time-Zone-Picker/")
+ await ctx.send(
+ "That's not a valid timezone. You can look them up at https://kevinnovak.github.io/Time-Zone-Picker/"
+ )
return
# set user's timezone to (verified) input zone
@@ -467,10 +484,11 @@ class Utils(commands.Cog):
# overwrite with new fair object
with open("fair.json", "w") as f:
- json.dump(fair, f, indent = 4)
+ json.dump(fair, f, indent=4)
- await ctx.send(f"{discord.utils.escape_mentions(ctx.message.author.display_name)} your timezone has been set to {timeZone}")
-
+ await ctx.send(
+ f"{discord.utils.escape_mentions(ctx.message.author.display_name)} your timezone has been set to {timeZone}"
+ )
# TODO (this also needs a better name)
# @commands.cooldown(1, 20, commands.BucketType.guild)
@@ -481,7 +499,6 @@ class Utils(commands.Cog):
# with open("fair.json", "r") as f:
# fair = json.load(f)
-
@commands.cooldown(1, 60, commands.BucketType.member)
@commands.command()
async def report(self, ctx, *, message=None):
@@ -531,20 +548,20 @@ class Utils(commands.Cog):
output = ", ".join([*commands])
await ctx.send(f"```List of custom commands:\n{output}```")
-# @commands.command(aliases=["calc"])
-# async def math(self, ctx, *, eqn: str):
-# try:
-# # Allow for proper absolute value notation
-# pipes = eqn.count("|")
-# eqn = eqn.replace("|", "abs(", pipes // 2).replace("|", ")", pipes // 2)
-#
-# result = subprocess.check_output(
-# f"echo 'scale = 10; {eqn}' | bc bc_funcs/*", shell=True
-# )
-# await ctx.send(result.decode("utf-8").replace("\\\n", "").strip())
-# except subprocess.CalledProcessError as err:
-# print(err)
-# await ctx.send("Something went wrong")
+ # @commands.command(aliases=["calc"])
+ # async def math(self, ctx, *, eqn: str):
+ # try:
+ # # Allow for proper absolute value notation
+ # pipes = eqn.count("|")
+ # eqn = eqn.replace("|", "abs(", pipes // 2).replace("|", ")", pipes // 2)
+ #
+ # result = subprocess.check_output(
+ # f"echo 'scale = 10; {eqn}' | bc bc_funcs/*", shell=True
+ # )
+ # await ctx.send(result.decode("utf-8").replace("\\\n", "").strip())
+ # except subprocess.CalledProcessError as err:
+ # print(err)
+ # await ctx.send("Something went wrong")
@commands.command()
async def retime(self, ctx, start_sec, end_sec, frames=0, framerate=30):