aboutsummaryrefslogtreecommitdiffstats
path: root/bot
diff options
context:
space:
mode:
authorGravatar Xithrius <[email protected]>2020-08-29 16:35:45 -0700
committerGravatar Xithrius <[email protected]>2020-08-29 16:37:17 -0700
commitd472389b564ed5e343d40750b092680fcdf1e9fc (patch)
tree5089fe2fe6ec99ed35976807ec471e89119e32dd /bot
parentUpdate bot/exts/evergreen/wolfram.py (diff)
Removed the time utility and replaced it with the arrow package.
Alphabetized the "Colours" NamedTuple in the constants file.
Diffstat (limited to 'bot')
-rw-r--r--bot/constants.py10
-rw-r--r--bot/exts/evergreen/wolfram.py3
-rw-r--r--bot/utils/time.py66
3 files changed, 6 insertions, 73 deletions
diff --git a/bot/constants.py b/bot/constants.py
index 4a97b9e0..f841193a 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -67,7 +67,7 @@ class Channels(NamedTuple):
off_topic_2 = 463035268514185226
python = 267624335836053506
reddit = 458224812528238616
- seasonalbot_commands = int(environ.get("CHANNEL_SEASONALBOT_COMMANDS", 607247579608121354))
+ seasonalbot_commands = int(environ.get("CHANNEL_SEASONALBOT_COMMANDS", 704362727778418798))
seasonalbot_voice = int(environ.get("CHANNEL_SEASONALBOT_VOICE", 606259004230074378))
staff_lounge = 464905259261755392
verification = 352442727016693763
@@ -93,11 +93,11 @@ class Colours:
dark_green = 0x1f8b4c
orange = 0xe67e22
pink = 0xcf84e0
+ purple = 0xb734eb
soft_green = 0x68c290
+ soft_orange = 0xf9cb54
soft_red = 0xcd6d6d
yellow = 0xf9f586
- purple = 0xb734eb
- soft_orange = 0xf9cb54
class Emojis:
@@ -190,8 +190,8 @@ class Tokens(NamedTuple):
class Wolfram(NamedTuple):
- user_limit_day = environ.get("WOLFRAM_USER_LIMIT_DAY", 10)
- guild_limit_day = environ.get("WOLFRAM_GUILD_LIMIT_DAY", 67)
+ user_limit_day = int(environ.get("WOLFRAM_USER_LIMIT_DAY", 10))
+ guild_limit_day = int(environ.get("WOLFRAM_GUILD_LIMIT_DAY", 67))
key = environ.get("WOLFRAM_API_KEY", None)
diff --git a/bot/exts/evergreen/wolfram.py b/bot/exts/evergreen/wolfram.py
index 4e1d284b..898e8d2a 100644
--- a/bot/exts/evergreen/wolfram.py
+++ b/bot/exts/evergreen/wolfram.py
@@ -3,15 +3,14 @@ from io import BytesIO
from typing import Callable, List, Optional, Tuple
from urllib import parse
+import arrow
import discord
-from dateutil.relativedelta import relativedelta
from discord import Embed
from discord.ext import commands
from discord.ext.commands import BucketType, Cog, Context, check, group
from bot.constants import Colours, STAFF_ROLES, Wolfram
from bot.utils.pagination import ImagePaginator
-from bot.utils.time import humanize_delta
log = logging.getLogger(__name__)
diff --git a/bot/utils/time.py b/bot/utils/time.py
deleted file mode 100644
index f37a025c..00000000
--- a/bot/utils/time.py
+++ /dev/null
@@ -1,66 +0,0 @@
-from dateutil.relativedelta import relativedelta
-
-
-def _stringify_time_unit(value: int, unit: str) -> str:
- """
- Returns a string to represent a value and time unit, ensuring that it uses the right plural form of the unit.
-
- >>> _stringify_time_unit(1, "seconds")
- "1 second"
- >>> _stringify_time_unit(24, "hours")
- "24 hours"
- >>> _stringify_time_unit(0, "minutes")
- "less than a minute"
- """
- if unit == "seconds" and value == 0:
- return "0 seconds"
- elif value == 1:
- return f"{value} {unit[:-1]}"
- elif value == 0:
- return f"less than a {unit[:-1]}"
- else:
- return f"{value} {unit}"
-
-
-def humanize_delta(delta: relativedelta, precision: str = "seconds", max_units: int = 6) -> str:
- """
- Returns a human-readable version of the relativedelta.
-
- precision specifies the smallest unit of time to include (e.g. "seconds", "minutes").
- max_units specifies the maximum number of units of time to include (e.g. 1 may include days but not hours).
- """
- if max_units <= 0:
- raise ValueError("max_units must be positive")
-
- units = (
- ("years", delta.years),
- ("months", delta.months),
- ("days", delta.days),
- ("hours", delta.hours),
- ("minutes", delta.minutes),
- ("seconds", delta.seconds),
- )
-
- # Add the time units that are >0, but stop at accuracy or max_units.
- time_strings = []
- unit_count = 0
- for unit, value in units:
- if value:
- time_strings.append(_stringify_time_unit(value, unit))
- unit_count += 1
-
- if unit == precision or unit_count >= max_units:
- break
-
- # Add the 'and' between the last two units, if necessary
- if len(time_strings) > 1:
- time_strings[-1] = f"{time_strings[-2]} and {time_strings[-1]}"
- del time_strings[-2]
-
- # If nothing has been found, just make the value 0 precision, e.g. `0 days`.
- if not time_strings:
- humanized = _stringify_time_unit(0, precision)
- else:
- humanized = ", ".join(time_strings)
-
- return humanized