Skip to content

Commit

Permalink
Add new mention_message config, black + ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
raidensakura committed May 22, 2023
1 parent fce12b7 commit 13ae200
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 162 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

name: Create and publish a Docker image
name: Docker Image

on:
push:
branches:
- 'main'
- 'stable'
- 'develop'
tags:
- 'v*'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/lints.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Modmail Workflow
name: Checks

on: [push, pull_request]

Expand All @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10']
python-version: ['3.10']

name: Python ${{ matrix.python-version }} on ubuntu-latest

Expand All @@ -22,8 +22,8 @@ jobs:
run: |
python -m pip install --upgrade pip pipenv
pipenv install --dev --system
- name: Pylint
run: pylint ./bot.py cogs/*.py core/*.py --exit-zero -r y
- name: Ruff
run: ruff . --no-fix
continue-on-error: true
- name: Black
run: |
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ however, insignificant breaking changes do not guarantee a major version bump, s
- New .env config option: `REGISTRY_PLUGINS_ONLY`, restricts to only allow adding registry plugins. ([PR #3247](https://github.com/modmail-dev/modmail/pull/3247))
- Added custom database name detection in `CONNECTION_URI`
- Added dpy and python version info in `?about` embed and credit for contributors
- New config option: `mention_message`, this will include an additional configurable message next to role mention on thread creation. Defaults to None.

### Changed
- Guild icons in embed footers and author urls now have a fixed size of 128. ([PR #3261](https://github.com/modmail-dev/modmail/pull/3261))
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ verify_ssl = true

[dev-packages]
black = "==22.3.0"
pylint = "~=2.9.3"
typing-extensions = "==4.2.0"
ruff = "*"

[packages]
aiohttp = "==3.8.1"
Expand Down
122 changes: 25 additions & 97 deletions Pipfile.lock

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

7 changes: 3 additions & 4 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@
import hashlib
import logging
import os
import platform
import re
import string
import struct
import sys
import platform
import typing
from datetime import datetime, timezone
from subprocess import PIPE
from types import SimpleNamespace

import discord
import isodate
from aiohttp import ClientSession, ClientResponseError
from aiohttp import ClientResponseError, ClientSession
from discord.ext import commands, tasks
from discord.ext.commands.view import StringView
from discord.ext.commands import MemberConverter
from discord.ext.commands.view import StringView
from emoji import UNICODE_EMOJI
from pkg_resources import parse_version


try:
# noinspection PyUnresolvedReferences
from colorama import init
Expand Down
10 changes: 4 additions & 6 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import asyncio
import re
from datetime import datetime, timezone
from datetime import timezone
from itertools import zip_longest
from typing import Optional, Union, List, Tuple, Literal
from types import SimpleNamespace
from typing import List, Literal, Optional, Tuple, Union

import discord
from dateutil import parser
from discord.ext import commands
from discord.ext.commands.view import StringView
from discord.ext.commands.cooldowns import BucketType
from discord.ext.commands.view import StringView
from discord.role import Role
from discord.utils import escape_markdown

from dateutil import parser

from core import checks
from core.models import DMDisabled, PermissionLevel, SimilarCategoryConverter, getLogger
from core.paginator import EmbedPaginatorSession
Expand Down Expand Up @@ -1647,7 +1646,6 @@ async def blocked(self, ctx):

roles = []
users = []
now = ctx.message.created_at

blocked_users = list(self.bot.blocked_users.items())
for id_, reason in blocked_users:
Expand Down
5 changes: 2 additions & 3 deletions cogs/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@
import sys
import typing
import zipfile
from importlib import invalidate_caches
from difflib import get_close_matches
from importlib import invalidate_caches
from pathlib import Path, PurePath
from re import match
from site import USER_SITE
from subprocess import PIPE

import discord
from discord.ext import commands

from pkg_resources import parse_version

from core import checks
from core.models import PermissionLevel, getLogger
from core.paginator import EmbedPaginatorSession
from core.utils import truncate, trigger_typing
from core.utils import trigger_typing, truncate

logger = getLogger(__name__)

Expand Down
39 changes: 28 additions & 11 deletions cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import os
import random
import re
import traceback
import sys
import traceback
from contextlib import redirect_stdout
from difflib import get_close_matches
from io import BytesIO, StringIO
Expand All @@ -24,16 +24,9 @@

from core import checks, utils
from core.changelog import Changelog
from core.models import (
HostingMethod,
InvalidConfigError,
PermissionLevel,
UnseenFormatter,
getLogger,
)
from core.utils import trigger_typing, truncate
from core.models import HostingMethod, InvalidConfigError, PermissionLevel, UnseenFormatter, getLogger
from core.paginator import EmbedPaginatorSession, MessagePaginatorSession

from core.utils import trigger_typing, truncate

logger = getLogger(__name__)

Expand Down Expand Up @@ -333,7 +326,6 @@ async def about(self, ctx):
desc += "an organised manner."
embed.description = desc

repo_url = "https://github.com/modmail-dev/modmail/graphs/contributors"
python_version = "{}.{}.{}".format(*sys.version_info[:3])
dpy_version = discord.__version__

Expand Down Expand Up @@ -710,6 +702,13 @@ async def mention(self, ctx, *user_or_role: Union[discord.Role, discord.Member,
Do not ping `@everyone` to set mention to everyone, use "everyone" or "all" instead.
You can also additionally configure a custom message to show after the mention.
You can use `[prefix]` as placeholder for bot prefix.
Examples:
- `{prefix}mention message Use [prefix]reply to reply`
- `{prefix}mention message disable`
Notes:
- Type only `{prefix}mention` to retrieve your current "mention" message.
- `{prefix}mention disable` to disable mention.
Expand All @@ -720,6 +719,24 @@ async def mention(self, ctx, *user_or_role: Union[discord.Role, discord.Member,
embed = discord.Embed(
title="Current mention:", color=self.bot.main_color, description=str(current)
)
elif isinstance(user_or_role[0], str) and user_or_role[0].lower() in ("message", "msg"):
option = user_or_role[1].lower()
if option == "disable":
embed = discord.Embed(
description="Disabled mention message on thread creation.",
color=self.bot.main_color,
)
self.bot.config["mention_message"] = None
else:
msg = " ".join(user_or_role[1:])
mention_msg = msg.replace("[prefix]", self.bot.prefix)
embed = discord.Embed(
title="Changed mention message!",
description=f'On thread creation the bot now says "{current} {mention_msg}".',
color=self.bot.main_color,
)
self.bot.config["mention_message"] = msg
await self.bot.config.update()
elif (
len(user_or_role) == 1
and isinstance(user_or_role[0], str)
Expand Down
7 changes: 3 additions & 4 deletions core/clients.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import secrets
import sys
from json import JSONDecodeError
from typing import Any, Dict, Union, Optional
from typing import Any, Dict, Optional, Union

import discord
from discord import Member, DMChannel, TextChannel, Message
from aiohttp import ClientResponse, ClientResponseError
from discord import DMChannel, Member, Message, TextChannel
from discord.ext import commands

from aiohttp import ClientResponseError, ClientResponse
from motor.motor_asyncio import AsyncIOMotorClient
from pymongo.errors import ConfigurationError
from pymongo.uri_parser import parse_uri
Expand Down
Loading

0 comments on commit 13ae200

Please sign in to comment.