Skip to content

Commit

Permalink
Merge branch 'main' into feat/custom-changelogger
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivansh-007 committed Oct 28, 2021
2 parents 30a5155 + ca172af commit ffd3cde
Show file tree
Hide file tree
Showing 17 changed files with 1,671 additions and 94 deletions.
16 changes: 9 additions & 7 deletions modmail/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ def __init__(self, **kwargs):
# allow only user mentions by default.
# ! NOTE: This may change in the future to allow roles as well
allowed_mentions = AllowedMentions(everyone=False, users=True, roles=False, replied_user=True)
# override passed kwargs if they are None
kwargs["case_insensitive"] = kwargs.get("case_insensitive", True)
# do not let the description be overridden.
kwargs["description"] = "Modmail bot by discord-modmail."
kwargs["status"] = kwargs.get("status", status)
kwargs["activity"] = kwargs.get("activity", activity)
kwargs["allowed_mentions"] = kwargs.get("allowed_mentions", allowed_mentions)
kwargs["command_prefix"] = kwargs.get("command_prefix", prefix)
kwargs["intents"] = kwargs.get("intents", REQUIRED_INTENTS)
super().__init__(
case_insensitive=True,
description="Modmail bot by discord-modmail.",
status=status,
activity=activity,
allowed_mentions=allowed_mentions,
command_prefix=prefix,
intents=REQUIRED_INTENTS,
**kwargs,
)

Expand Down
2 changes: 1 addition & 1 deletion modmail/extensions/utils/error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

ERROR_COLOUR = discord.Colour.red()

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

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

Expand Down
41 changes: 41 additions & 0 deletions modmail/utils/time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import datetime
import enum
import typing

import arrow


class TimeStampEnum(enum.Enum):
"""
Timestamp modes for discord.
Full docs on this format are viewable here:
https://discord.com/developers/docs/reference#message-formatting
"""

# fmt: off
SHORT_TIME = "t" # 16:20
LONG_TIME = "T" # 16:20:30
SHORT_DATE = "d" # 20/04/2021
LONG_DATE = "D" # 20 April 2021
SHORT_DATE_TIME = "f" # 20 April 2021 16:20
LONG_DATE_TIME = "F" # Tuesday, 20 April 2021 16:20
RELATIVE_TIME = "R" # 2 months ago

# fmt: on
# DEFAULT alised to the default, so for all purposes, it behaves like SHORT_DATE_TIME, including the name
DEFAULT = SHORT_DATE_TIME


TypeTimes = typing.Union[arrow.Arrow, datetime.datetime]


def get_discord_formatted_timestamp(
timestamp: TypeTimes, format: TimeStampEnum = TimeStampEnum.DEFAULT
) -> str:
"""
Return a discord formatted timestamp from a datetime compatiable datatype.
`format` must be an enum member of TimeStampEnum. Default style is SHORT_DATE_TIME
"""
return f"<t:{int(timestamp.timestamp())}:{format.value}>"
104 changes: 42 additions & 62 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ isort = "^5.9.2"
pep8-naming = "~=0.11"
# testing
codecov = "^2.1.11"
coverage = { extras = ["toml"], version = "^5.5" }
coverage = { extras = ["toml"], version = "^6.0.2" }
pytest = "^6.2.4"
pytest-asyncio = "^0.15.1"
pytest-cov = "^2.12.1"
pytest-cov = "^3.0.0"
pytest-dependency = "^0.5.1"
pytest-sugar = "^0.9.4"
pytest-xdist = { version = "^2.3.0", extras = ["psutil"] }
Expand All @@ -67,13 +67,13 @@ build-backend = "poetry.core.masonry.api"

[tool.coverage.run]
branch = true
source_pkgs = ["modmail"]
source_pkgs = ['modmail', 'tests.modmail']
omit = ["modmail/plugins/**.*"]

[tool.pytest.ini_options]
addopts = "--cov --cov-report="
minversion = "6.0"
testpaths = ["tests"]
testpaths = ["tests/modmail"]

[tool.black]
line-length = 110
Expand All @@ -93,3 +93,4 @@ lint = { cmd = "pre-commit run --all-files", help = "Checks all files for CI err
precommit = { cmd = "pre-commit install --install-hooks", help = "Installs the precommit hook" }
report = { cmd = "coverage report", help = "Show coverage report from previously run tests." }
test = { cmd = "pytest -n auto --dist loadfile", help = "Runs tests and save results to a coverage report" }
test_mocks = { cmd = 'pytest tests/test_mocks.py', help = 'Runs the tests on the mock files. They are excluded from the main test suite.' }
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest


def pytest_report_header(config):
def pytest_report_header(config) -> str:
"""Pytest headers."""
return "package: modmail"
Loading

0 comments on commit ffd3cde

Please sign in to comment.