Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from chamburr:master #4

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
eb3b6e9
build(deps): bump api dependencies
chamburr Oct 29, 2022
2838805
chore(web): update format check command
chamburr Nov 17, 2022
7201ba0
chore: use pre-built docker image
chamburr Nov 17, 2022
fb217bf
ci: add drone ci
chamburr Nov 17, 2022
130a1c9
ci: install dependencies
chamburr Nov 17, 2022
84f96bf
style: format code
chamburr Nov 17, 2022
a314271
style: fix line too long
chamburr Nov 17, 2022
21efae5
fix(bot): downgrade aiohttp
chamburr Nov 17, 2022
f7b5f45
chore: remove plausible
chamburr Dec 14, 2022
363758d
build: update docker images
chamburr Dec 14, 2022
b8b0c9b
fix: add checks for bad username
chamburr Dec 25, 2022
1d5233b
fix: copy message reference data
chamburr Dec 25, 2022
ea3c36a
chore: move entrypoint script to bot
chamburr Dec 25, 2022
9b3ed25
fix(web): replace environment with node_env
chamburr Dec 25, 2022
5438965
chore(api): remove unused environment
chamburr Dec 25, 2022
3966a47
fix: update docker compose
chamburr Dec 28, 2022
ba59416
chore: reorder environment variables
chamburr Dec 28, 2022
8fd0544
docs: update hosting instructions
chamburr Dec 28, 2022
1c73e7d
fix(api): fix build errors
chamburr Dec 28, 2022
24661fc
fix(bot): update prometheus
chamburr Dec 30, 2022
c800196
fix(bot): remove emojis from server info
chamburr Dec 30, 2022
1d6cb62
build(bot): update dependencies
chamburr Dec 30, 2022
8adf5fb
fix(bot): await message ack coroutine
chamburr Dec 30, 2022
37f7d27
fix(web): fix runtime variables
chamburr Dec 31, 2022
17cbdf2
fix(api): fix docker segfault
chamburr Dec 31, 2022
94549d8
fix(api): fix paypal payment webhook
chamburr Jan 4, 2023
b983fc3
feat: add ticket creation toggle (#145)
iamshoXy Mar 5, 2023
5ae0682
release: version 3.3.0
chamburr Mar 7, 2023
1c5afa5
chore: update copyright (#146)
dlsnyder8 Mar 19, 2023
99fa3c2
feat: add error message for maximum channels (#148)
Ivniinvi Apr 15, 2023
4283606
fix(web): update logs regex for new username
chamburr May 20, 2023
552063d
fix(web): add static folder to docker
chamburr Jun 29, 2023
c7f5d94
chore(bot): remove bfd stats
chamburr Aug 22, 2023
eeba9d1
fix(bot): fix logging attachment link
chamburr Sep 26, 2023
588e54e
build: update docker images
chamburr Sep 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .drone/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
kind: pipeline
name: docker

steps:
- name: publish api
image: plugins/docker
settings:
repo: chamburr/modmail-api
auto_tag: true
dockerfile: docker/api/Dockerfile
username:
from_secret: docker_username
password:
from_secret: docker_password
- name: publish bot
image: plugins/docker
settings:
repo: chamburr/modmail-bot
auto_tag: true
dockerfile: docker/bot/Dockerfile
username:
from_secret: docker_username
password:
from_secret: docker_password
- name: publish web
image: plugins/docker
settings:
repo: chamburr/modmail-web
auto_tag: true
dockerfile: docker/web/Dockerfile
username:
from_secret: docker_username
password:
from_secret: docker_password

trigger:
event:
- push
- tag
branch:
- master
29 changes: 29 additions & 0 deletions .drone/format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
kind: pipeline
name: format

steps:
- name: format rust
image: rust
commands:
- cd web
- rustup component add rustfmt
- cargo fmt --check
- name: format node
image: node
commands:
- cd web
- yarn install
- yarn --silent format:check
- name: format python
image: python
commands:
- pip install isort black
- isort --check .
- black --check --line-length 100 .

trigger:
event:
- push
branch:
- master
28 changes: 28 additions & 0 deletions .drone/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
kind: pipeline
name: lint

steps:
- name: lint rust
image: rust
commands:
- cd web
- rustup component add clippy
- cargo clippy
- name: lint node
image: node
commands:
- cd web
- yarn install
- yarn --silent lint
- name: lint python
image: python
commands:
- pip install flake8
- flake8

trigger:
event:
- push
branch:
- master
11 changes: 5 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ PATRON_CHANNEL=
#################### Database ####################

# PostgreSQL server
POSTGRES_DATABASE=modmail
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=
POSTGRES_HOST=127.0.0.1
POSTGRES_PORT=5432
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=
POSTGRES_DATABASE=modmail

# Redis server
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=

# RabbitMQ server
RABBIT_USERNAME=guest
RABBIT_PASSWORD=guest
RABBIT_HOST=127.0.0.1
RABBIT_PORT=5672
RABBIT_USERNAME=guest
RABBIT_PASSWORD=guest

##################### Server #####################

Expand All @@ -81,4 +81,3 @@ TOPGG_TOKEN=
DBOTS_TOKEN=
DBL_TOKEN=
BOD_TOKEN=
BFD_TOKEN=
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ enable the server member intent and the message content intent for the bot to fu
Then, install Git and Docker on your machine. Clone this repository, copy `docker/.env.example` to
`docker/.env` and fill in all the configurations.

Finally, run the following commands to build and run ModMail. Please note that the initial build
may take 10 to 15 minutes, depending on your machine. Subsequent builds would be much faster.
Finally, use the following commands run ModMail.

```
cd docker
Expand Down
2 changes: 1 addition & 1 deletion classes/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,4 @@ async def start(self, worker=True):
async for message in queue_iter:
async with message.process(ignore_processed=True):
await self.receive_message(message.body)
message.ack()
await message.ack()
3 changes: 2 additions & 1 deletion classes/message.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import logging

from discord import message, utils
Expand Down Expand Up @@ -33,7 +34,7 @@ def __init__(self, *, state, channel, data):
self.content = data["content"]
self.nonce = data.get("nonce")

ref = data.get("message_reference")
ref = copy.copy(data.get("message_reference"))
self.reference = MessageReference.with_state(state, ref) if ref is not None else None

try:
Expand Down
57 changes: 40 additions & 17 deletions cogs/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,28 @@ async def anonymous(self, ctx):
Embed(f"Anonymous messaging is {'enabled' if data[10] is False else 'disabled'}.")
)

@checks.in_database()
@checks.has_permissions(administrator=True)
@commands.guild_only()
@commands.command(
description="Toggle whether tickets can be created, optionally with reason if disabling.",
aliases=["enable", "disable"],
usage="toggle [reason]",
)
async def toggle(self, ctx, *, reason: str = ""):
data = await tools.get_data(self.bot, ctx.guild.id)

async with self.bot.pool.acquire() as conn:
await conn.execute(
"UPDATE data SET toggle=$1 WHERE guild=$2",
reason if data[12] is None else None,
ctx.guild.id,
)

await ctx.send(
Embed(f"Ticket creation is {'disabled' if data[12] is None else 'enabled'}.")
)

@checks.in_database()
@checks.has_permissions(administrator=True)
@commands.guild_only()
Expand All @@ -403,20 +425,26 @@ async def anonymous(self, ctx):
async def viewconfig(self, ctx):
data = await tools.get_data(self.bot, ctx.guild.id)
category = await ctx.guild.get_channel(data[2])
logging_channel = await ctx.guild.get_channel(data[4])
logging = await ctx.guild.get_channel(data[4])

access_roles = []
access = []
for role in data[3]:
access_roles.append(f"<@&{role}>")
access.append(f"<@&{role}>")

ping_roles = []
ping = []
for role in data[8]:
if role == -1:
ping_roles.append("@here")
ping.append("@here")
elif role == ctx.guild.id:
ping_roles.append("@everyone")
ping.append("@everyone")
else:
ping_roles.append(f"<@&{role}>")
ping.append(f"<@&{role}>")

toggle = data[12]
if toggle and len(toggle) > 989:
toggle = toggle[:986] + "..."
elif toggle == "":
toggle = "No reason was provided."

greeting = data[5]
if greeting and len(greeting) > 1000:
Expand All @@ -429,18 +457,13 @@ async def viewconfig(self, ctx):
embed = Embed(title="Server Configurations")
embed.add_field("Prefix", ctx.prefix)
embed.add_field("Category", "*Not set*" if category is None else category.name)
embed.add_field(
"Access Roles",
"*Not set*" if len(access_roles) == 0 else " ".join(access_roles),
)
embed.add_field("Ping Roles", "*Not set*" if len(ping_roles) == 0 else " ".join(ping_roles))
embed.add_field(
"Logging",
"*Not set*" if logging_channel is None else f"<#{logging_channel.id}>",
)
embed.add_field("Access Roles", "*Not set*" if len(access) == 0 else " ".join(access))
embed.add_field("Ping Roles", "*Not set*" if len(ping) == 0 else " ".join(ping))
embed.add_field("Logging", "*Not set*" if logging is None else f"<#{logging.id}>")
embed.add_field("Advanced Logging", "Enabled" if data[7] is True else "Disabled")
embed.add_field("Anonymous Messaging", "Enabled" if data[10] is True else "Disabled")
embed.add_field("Command Only Mode", "Enabled" if data[11] is True else "Disabled")
embed.add_field("Command Only", "Enabled" if data[11] is True else "Disabled")
embed.add_field("Ticket Creation", "Enabled" if toggle is None else f"Disabled ({toggle})")
embed.add_field("Greeting Message", "*Not set*" if greeting is None else greeting, False)
embed.add_field("Closing Message", "*Not set*" if closing is None else closing, False)

Expand Down
2 changes: 1 addition & 1 deletion cogs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ async def close_channel(self, ctx, reason, anon: bool = False):
except discord.Forbidden:
return

log_url = msg.attachments[0].url[39:-4]
log_url = msg.attachments[0].url.split("?")[0][39:-4]
log_url = log_url.replace("modmail_log_", "")
log_url = [hex(int(some_id))[2:] for some_id in log_url.split("/")]
log_url = f"{self.bot.config.BASE_URI}/logs/{'-'.join(log_url)}"
Expand Down
40 changes: 33 additions & 7 deletions cogs/direct_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ async def send_mail(self, message, guild):
break

if channel is None:
if data[12] is not None:
embed = ErrorEmbed(
"Ticket Creation Disabled",
data[12] if data[12] else "No reason was provided.",
timestamp=True,
)
embed.set_footer(f"{guild.name} | {guild.id}", guild.icon_url)
await message.channel.send(embed)
return

self.bot.prom.tickets.inc({})

name = "".join(
Expand All @@ -82,13 +92,29 @@ async def send_mail(self, message, guild):
"not change this)",
)
except discord.HTTPException as e:
await message.channel.send(
ErrorEmbed(
"An HTTPException error occurred. Please contact an admin on the server "
f"with the following information: {e.text} ({e.code})."
if "Contains words not allowed" in e.text:
channel = await guild.create_text_channel(
name=message.author.id,
category=category,
topic=f"ModMail Channel {message.author.id} {message.channel.id} (Please "
"do not change this)",
)
)
return
elif "Maximum number of channels" in e.text:
await message.channel.send(
ErrorEmbed(
"The server has reached the maximum number of active tickets. Please "
"try again later."
)
)
return
else:
await message.channel.send(
ErrorEmbed(
"An HTTPException error occurred. Please contact an admin on the "
f"server with the following information: {e.text} ({e.code})."
)
)
return

log_channel = await guild.get_channel(data[4])
if log_channel:
Expand Down Expand Up @@ -310,7 +336,7 @@ async def on_message(self, message):
confirmation = False
if self.bot.config.DEFAULT_SERVER is not None:
guild = await self.bot.get_guild(int(self.bot.config.DEFAULT_SERVER))
else:
else:
async for msg in message.channel.history(limit=30):
if (
msg.author.id == self.bot.id
Expand Down
1 change: 0 additions & 1 deletion cogs/miscellaneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ async def serverinfo(self, ctx):
embed.add_field("Members", guild.member_count)
embed.add_field("Channels", str(len(await guild.channels())))
embed.add_field("Roles", str(len(await guild.roles())))
embed.add_field("Emojis", str(len(await guild.emojis())))

if guild.icon:
embed.set_thumbnail(guild.icon_url)
Expand Down
5 changes: 0 additions & 5 deletions docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ BOT_TOKEN=
BOT_CLIENT_ID=
BOT_CLIENT_SECRET=

# Activity information
STATUS=online
ACTIVITY_TYPE=0
ACTIVITY_NAME="DM to Contact Staff | =help"

# Default command prefix
DEFAULT_PREFIX==

Expand Down
8 changes: 5 additions & 3 deletions docker/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM rust:1.60-alpine AS builder
FROM rust:1.72-alpine AS builder

ENV RUSTFLAGS "-C target-feature=-crt-static"

RUN apk add --no-cache musl-dev openssl-dev

Expand All @@ -15,9 +17,9 @@ COPY web/src ./src

RUN cargo build --release

FROM alpine:latest
FROM alpine:3.18

RUN apk add --no-cache dumb-init
RUN apk add --no-cache dumb-init libgcc libssl1.1

WORKDIR /app

Expand Down
6 changes: 3 additions & 3 deletions docker/bot/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.60-slim-buster AS builder
FROM rust:1.72-slim-buster AS builder

RUN apt update && apt install -y musl-dev libpq-dev

Expand All @@ -8,7 +8,7 @@ WORKDIR /build

RUN cp /usr/local/cargo/bin/diesel ./

FROM python:3.10-slim-buster
FROM python:3.11-slim-buster

RUN apt update && apt install -y dumb-init git gcc netcat libpq-dev
RUN rm -rf /var/lib/apt/lists/*
Expand All @@ -23,7 +23,7 @@ RUN mkdir logs

COPY --from=builder /build ./bin

COPY docker/entrypoint.sh ./bin/
COPY docker/bot/entrypoint.sh ./bin/
COPY main.py worker.py ./
COPY classes ./classes
COPY cogs ./cogs
Expand Down
File renamed without changes.
Loading