Skip to content

Commit

Permalink
Merge branch 'main' into feat/plugin-install
Browse files Browse the repository at this point in the history
  • Loading branch information
onerandomusername committed Apr 21, 2022
2 parents 6214cdd + df5dbb9 commit bfba8e2
Show file tree
Hide file tree
Showing 25 changed files with 2,409 additions and 139 deletions.
9 changes: 9 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Breaking
- Bot now requires a `RELAY_CHANNEL_ID` configuration variable. (#53)
- This is where tickets with users will be relayed.
- At a later point in time, this will be additionally included in a configuration command.

### Added
- Threads system (#53)
- Plugin installation and uninstall system (#69)
- Messages can now be relayed between a user and a server.
- NOTE: There is not a database yet, so none of these messages are stored.
- Added Dispatcher system, although it is not hooked into important features like thread creation yet. (#71)
- Officially support python 3.10 (#119)
- Officially support windows and macos (#121)
Expand All @@ -17,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Embedified the meta commands so they have a nicer UI (#78)
- Improved the logging system to allow trace logging and a specific logging directory to be configured. (#118)

## [0.2.0] - 2021-09-29

Expand Down
25 changes: 9 additions & 16 deletions modmail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
import logging
import logging.handlers
import os
from pathlib import Path

import coloredlogs

from modmail.log import ModmailLogger, get_log_level_from_name
from modmail import log


try:
Expand All @@ -22,24 +21,17 @@
if os.name == "nt":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

logging.TRACE = 5
logging.NOTICE = 25
logging.addLevelName(logging.TRACE, "TRACE")
logging.addLevelName(logging.NOTICE, "NOTICE")


LOG_FILE_SIZE = 8 * (2**10) ** 2 # 8MB, discord upload limit

# this logging level is set to logging.TRACE because if it is not set to the lowest level,
# the child level will be limited to the lowest level this is set to.
ROOT_LOG_LEVEL = get_log_level_from_name(os.environ.get("MODMAIL_LOG_LEVEL", logging.TRACE))

ROOT_LOG_LEVEL = log.get_logging_level()
FMT = "%(asctime)s %(levelname)10s %(name)15s - [%(lineno)5d]: %(message)s"
DATEFMT = "%Y/%m/%d %H:%M:%S"

logging.setLoggerClass(ModmailLogger)
logging.setLoggerClass(log.ModmailLogger)

# Set up file logging
log_file = Path("logs", "bot.log")
# Set up file logging relative to the current path
log_file = log.get_log_dir() / "bot.log"
log_file.parent.mkdir(parents=True, exist_ok=True)

# file handler
Expand All @@ -64,7 +56,7 @@
coloredlogs.install(level=logging.TRACE, fmt=FMT, datefmt=DATEFMT)

# Create root logger
root: ModmailLogger = logging.getLogger()
root: log.ModmailLogger = logging.getLogger()
root.setLevel(ROOT_LOG_LEVEL)
root.addHandler(file_handler)

Expand All @@ -74,4 +66,5 @@
# Set asyncio logging back to the default of INFO even if asyncio's debug mode is enabled.
logging.getLogger("asyncio").setLevel(logging.INFO)

__all__ = ()
# set up trace loggers
log.set_logger_levels()
5 changes: 4 additions & 1 deletion modmail/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from modmail.log import ModmailLogger
from modmail.utils.cogs import ModmailCog
from modmail.utils.extensions import BOT_MODE, EXTENSIONS, NO_UNLOAD, walk_extensions
from modmail.utils.threads import Ticket


REQUIRED_INTENTS = Intents(
Expand All @@ -43,9 +44,11 @@ class ModmailBot(commands.Bot):
mode: int
dispatcher: Dispatcher

_tickets: t.Dict[int, Ticket] = dict()

def __init__(self, **kwargs):
self.config = config()
self.start_time: t.Optional[arrow.Arrow] = None # arrow.utcnow()
self.start_time: arrow.Arrow = arrow.utcnow()
self.http_session: t.Optional[aiohttp.ClientSession] = None
self.dispatcher = Dispatcher()

Expand Down
22 changes: 22 additions & 0 deletions modmail/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import types
import typing
from collections import defaultdict
from typing import Optional

import attr
import desert
Expand Down Expand Up @@ -383,6 +384,26 @@ class EmojiConfig:
)


@attr.mutable(slots=True)
class ThreadConfig:
"""Thread configuration."""

thread_mention_role_id: Optional[int] = attr.ib(
default=0,
metadata={
METADATA_TABLE: ConfigMetadata(
description="Role to mention on ticket creation.",
)
},
converter=int,
)
relay_channel_id: Optional[int] = attr.ib(
default=0,
metadata={METADATA_TABLE: ConfigMetadata(description="Channel to use for creating tickets.")},
converter=int,
)


@attr.s(auto_attribs=True, slots=True)
class BaseConfig:
"""
Expand All @@ -406,6 +427,7 @@ class BaseConfig:
},
)
emojis: EmojiConfig = EmojiConfig()
threads: ThreadConfig = ThreadConfig()


# build configuration
Expand Down
2 changes: 1 addition & 1 deletion modmail/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pycares==4.1.2
pycparser==2.20
pyreadline3==3.3
python-dateutil==2.8.2
python-dotenv==0.19.0
python-dotenv==0.19.2
pyyaml==5.4.1
rapidfuzz==2.0.10
six==1.16.0
Expand Down
4 changes: 4 additions & 0 deletions modmail/default_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ production = true
[emojis]
failure = ":x:"
success = ":thumbsup:"

[threads]
relay_channel_id = 0
thread_mention_role_id = 0
3 changes: 3 additions & 0 deletions modmail/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ dev:
emojis:
failure: ':x:'
success: ':thumbsup:'
threads:
relay_channel_id: 0
thread_mention_role_id: 0
2 changes: 1 addition & 1 deletion modmail/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
from typing import Callable, Coroutine, Dict, List, Optional, Tuple, Union

from modmail import ModmailLogger
from modmail.log import ModmailLogger
from modmail.utils.general import module_function_disidenticality


Expand Down
Loading

0 comments on commit bfba8e2

Please sign in to comment.