Skip to content

Commit ffd3cde

Browse files
authored
Merge branch 'main' into feat/custom-changelogger
2 parents 30a5155 + ca172af commit ffd3cde

17 files changed

+1671
-94
lines changed

modmail/bot.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ def __init__(self, **kwargs):
4949
# allow only user mentions by default.
5050
# ! NOTE: This may change in the future to allow roles as well
5151
allowed_mentions = AllowedMentions(everyone=False, users=True, roles=False, replied_user=True)
52+
# override passed kwargs if they are None
53+
kwargs["case_insensitive"] = kwargs.get("case_insensitive", True)
54+
# do not let the description be overridden.
55+
kwargs["description"] = "Modmail bot by discord-modmail."
56+
kwargs["status"] = kwargs.get("status", status)
57+
kwargs["activity"] = kwargs.get("activity", activity)
58+
kwargs["allowed_mentions"] = kwargs.get("allowed_mentions", allowed_mentions)
59+
kwargs["command_prefix"] = kwargs.get("command_prefix", prefix)
60+
kwargs["intents"] = kwargs.get("intents", REQUIRED_INTENTS)
5261
super().__init__(
53-
case_insensitive=True,
54-
description="Modmail bot by discord-modmail.",
55-
status=status,
56-
activity=activity,
57-
allowed_mentions=allowed_mentions,
58-
command_prefix=prefix,
59-
intents=REQUIRED_INTENTS,
6062
**kwargs,
6163
)
6264

modmail/extensions/utils/error_handler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
ERROR_COLOUR = discord.Colour.red()
2020

21-
ERROR_TITLE_REGEX = re.compile(r"(?<=[a-zA-Z])([A-Z])(?=[a-z])")
21+
ERROR_TITLE_REGEX = re.compile(r"((?<=[a-z])[A-Z]|(?<=[a-zA-Z])[A-Z](?=[a-z]))")
2222

2323
ANY_DEV_MODE = BOT_MODE & (BotModes.DEVELOP.value + BotModes.PLUGIN_DEV.value)
2424

modmail/utils/time.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import datetime
2+
import enum
3+
import typing
4+
5+
import arrow
6+
7+
8+
class TimeStampEnum(enum.Enum):
9+
"""
10+
Timestamp modes for discord.
11+
12+
Full docs on this format are viewable here:
13+
https://discord.com/developers/docs/reference#message-formatting
14+
"""
15+
16+
# fmt: off
17+
SHORT_TIME = "t" # 16:20
18+
LONG_TIME = "T" # 16:20:30
19+
SHORT_DATE = "d" # 20/04/2021
20+
LONG_DATE = "D" # 20 April 2021
21+
SHORT_DATE_TIME = "f" # 20 April 2021 16:20
22+
LONG_DATE_TIME = "F" # Tuesday, 20 April 2021 16:20
23+
RELATIVE_TIME = "R" # 2 months ago
24+
25+
# fmt: on
26+
# DEFAULT alised to the default, so for all purposes, it behaves like SHORT_DATE_TIME, including the name
27+
DEFAULT = SHORT_DATE_TIME
28+
29+
30+
TypeTimes = typing.Union[arrow.Arrow, datetime.datetime]
31+
32+
33+
def get_discord_formatted_timestamp(
34+
timestamp: TypeTimes, format: TimeStampEnum = TimeStampEnum.DEFAULT
35+
) -> str:
36+
"""
37+
Return a discord formatted timestamp from a datetime compatiable datatype.
38+
39+
`format` must be an enum member of TimeStampEnum. Default style is SHORT_DATE_TIME
40+
"""
41+
return f"<t:{int(timestamp.timestamp())}:{format.value}>"

poetry.lock

+42-62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+5-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ isort = "^5.9.2"
4545
pep8-naming = "~=0.11"
4646
# testing
4747
codecov = "^2.1.11"
48-
coverage = { extras = ["toml"], version = "^5.5" }
48+
coverage = { extras = ["toml"], version = "^6.0.2" }
4949
pytest = "^6.2.4"
5050
pytest-asyncio = "^0.15.1"
51-
pytest-cov = "^2.12.1"
51+
pytest-cov = "^3.0.0"
5252
pytest-dependency = "^0.5.1"
5353
pytest-sugar = "^0.9.4"
5454
pytest-xdist = { version = "^2.3.0", extras = ["psutil"] }
@@ -67,13 +67,13 @@ build-backend = "poetry.core.masonry.api"
6767

6868
[tool.coverage.run]
6969
branch = true
70-
source_pkgs = ["modmail"]
70+
source_pkgs = ['modmail', 'tests.modmail']
7171
omit = ["modmail/plugins/**.*"]
7272

7373
[tool.pytest.ini_options]
7474
addopts = "--cov --cov-report="
7575
minversion = "6.0"
76-
testpaths = ["tests"]
76+
testpaths = ["tests/modmail"]
7777

7878
[tool.black]
7979
line-length = 110
@@ -93,3 +93,4 @@ lint = { cmd = "pre-commit run --all-files", help = "Checks all files for CI err
9393
precommit = { cmd = "pre-commit install --install-hooks", help = "Installs the precommit hook" }
9494
report = { cmd = "coverage report", help = "Show coverage report from previously run tests." }
9595
test = { cmd = "pytest -n auto --dist loadfile", help = "Runs tests and save results to a coverage report" }
96+
test_mocks = { cmd = 'pytest tests/test_mocks.py', help = 'Runs the tests on the mock files. They are excluded from the main test suite.' }

tests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

33

4-
def pytest_report_header(config):
4+
def pytest_report_header(config) -> str:
55
"""Pytest headers."""
66
return "package: modmail"

0 commit comments

Comments
 (0)