Skip to content

Commit 27e63d4

Browse files
committed
merge: Merge branch 'dev' into feat/highlight
2 parents 109a920 + 7784781 commit 27e63d4

25 files changed

+257
-264
lines changed

.github/CHANGELOG.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# v3.6 (Structure Refactor)
22

3-
> **Info**
3+
> **Note**
44
>
55
> Version 3.6.x is mostly about refactoring the project structure since
66
> previously functions and constants are all over the place that it's starting
77
> to get harder to find what I'm looking for.
88
9-
## 3.6.0 (Project Structure Refactor)
9+
## 3.6.1 (Project Structure Refactor - Part 1.5 A.K.A Hotfix)
10+
11+
- [**Fixed**] Fixed issues related to `import tse`
12+
- [**Fixed**] Aerich caused the bot to crash in production environment
13+
14+
## 3.6.0 (Project Structure Refactor - Part 1)
1015

1116
### Bugfixes
1217
- [**Fixed**] Fixed potential error related to user without avatar
@@ -36,6 +41,8 @@
3641
- [**Improved**] Moved JSON (and Blacklist) and Cache (and its properties) into `core.data`
3742
- [**Changed**] Removed `CMDName`
3843
- [**Added**] Initial ZeroMQ support for Dashboard
44+
- [**Improved**] `ccModeCheck` is now an actual check (`hasCCPriviledge`)
45+
- [**Improved**] CustomCommand is now a converter
3946

4047
# v3.5 (Overhaul an Overhaul?)
4148

.github/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
## About
2121

22+
> **Note**
23+
>
24+
> `dev` branch is used mostly for development and generally considered as unstable, to host the bot it's recommended to use `overhaul` branch or release tags instead!
25+
2226
**`Z3R0`** (codename **`ziBot`**) is a **free** and **open-source** multi-purpose discord bot, created for fun in the middle of quarantine. Used to be fork of [Steve-Bot](https://github.com/MCBE-Speedrunning/Steve-Bot) by MCBE Speedrunning Moderators.
2327

2428
### Features
@@ -104,7 +108,7 @@ More feature coming soon!
104108
> Python 3.10+ (3.10.9 is recommended) is required to host this bot!
105109

106110
- Download this repository by executing `git clone https://github.com/ZiRO-Bot/Z3R0.git`
107-
or click "Code" -> "Download ZIP"
111+
or click "Code" -> "Download ZIP" (be sure to choose `overhaul` branch first!)
108112
- Install poetry by executing this command,
109113

110114
```zsh

.github/workflows/build.yml

+32-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
name: Nightly Build
1+
name: Build
22

33
on:
44
push:
55
branches:
66
- dev
7+
- overhaul
8+
tags:
9+
- 3.*
710

811
permissions:
912
contents: read
@@ -31,10 +34,37 @@ jobs:
3134
username: ${{ github.repository_owner }}
3235
password: ${{ secrets.GITHUB_TOKEN }}
3336

34-
- name: Build and push
37+
- name: Get tag name
38+
if: startsWith(github.ref, 'refs/tags/') && github.repository == 'ziro-bot/z3r0'
39+
run: |
40+
set -x
41+
echo "VERSION_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
42+
43+
- name: Build and push (Nightly)
3544
uses: docker/build-push-action@v4
45+
if: ${{ !startsWith(github.ref, 'refs/tags/') && github.ref_name == 'dev' && github.repository == 'ziro-bot/z3r0' }}
3646
with:
3747
context: .
3848
file: ./docker/Dockerfile
3949
push: true
4050
tags: ghcr.io/ziro-bot/z3r0:nightly
51+
52+
- name: Build and push (Canary)
53+
uses: docker/build-push-action@v4
54+
if: ${{ !startsWith(github.ref, 'refs/tags/') && github.ref_name == 'overhaul' && github.repository == 'ziro-bot/z3r0' }}
55+
with:
56+
context: .
57+
file: ./docker/Dockerfile
58+
push: true
59+
tags: ghcr.io/ziro-bot/z3r0:canary
60+
61+
- name: Build and push (Release)
62+
uses: docker/build-push-action@v4
63+
if: startsWith(github.ref, 'refs/tags/') && github.repository == 'ziro-bot/z3r0'
64+
with:
65+
context: .
66+
file: ./docker/Dockerfile
67+
push: true
68+
tags: |
69+
ghcr.io/ziro-bot/z3r0:latest
70+
ghcr.io/ziro-bot/z3r0:${{ env.VERSION_TAG }}

aerich.ini

-4
This file was deleted.

aerichConfig.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
except ImportError:
1111
dbUrl = os.environ["ZIBOT_DB_URL"]
1212

13-
cfg = Config("", dbUrl)
13+
cfg = Config("", dbUrl, useAerich=True)
14+
t = cfg.tortoiseConfig

docker/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ ENV PATH="/venv/bin:${PATH}" \
4141
VIRTUAL_ENV="/venv"
4242

4343
COPY --from=builder /venv /venv
44+
COPY --from=builder /app/pyproject.toml /app/
4445
COPY --from=builder /app/src/ /app/src
4546
COPY assets/ /app/assets
4647
COPY docker/__main__.py ./

poetry.lock

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

pyproject.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "Z3R0"
3-
version = "3.6.0"
3+
version = "3.6.1"
44
description = "A multi-purpose open source discord bot"
55
authors = ["null2264"]
66
license = "MPL-2.0"
@@ -43,7 +43,7 @@ black = "^22.10.0"
4343
isort = "^5.10.1"
4444
pre-commit = "^2.13.0"
4545
pyproject-flake8 = "^0.0.1-alpha.2"
46-
aerich = "^0.6.2"
46+
aerich = "0.7.1"
4747

4848
[tool.poetry.group.test]
4949

@@ -84,9 +84,9 @@ multi_line_output = 3
8484
lines_after_imports = 2
8585

8686
[tool.aerich]
87-
tortoise_orm = "config.TORTOISE_ORM"
88-
location = "./migrations"
87+
tortoise_orm = "aerichConfig.t"
88+
location = "./src/main/migrations"
8989
src_folder = "./."
9090

9191
[tool.pytest.ini_options]
92-
pythonpath = ["src"]
92+
pythonpath = ["."]

src/main/core/bot.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,25 @@ async def on_ready(self) -> None:
232232
self.logger.warning("Ready: {0} (ID: {0.id})".format(self.user))
233233

234234
async def zmqBind(self):
235-
context = zmq.asyncio.Context.instance()
236235
pubPort = self.config.zmqPorts.get("PUB")
236+
subPort = self.config.zmqPorts.get("SUB")
237+
repPort = self.config.zmqPorts.get("REP")
238+
239+
if not pubPort and not subPort and not repPort:
240+
return
241+
242+
context = zmq.asyncio.Context.instance()
243+
237244
if pubPort:
238245
self.pubSocket = context.socket(zmq.PUB)
239246
self.pubSocket.bind(f"tcp://*:{pubPort}")
240247

241-
subPort = self.config.zmqPorts.get("SUB")
242248
if subPort:
243249
self.subSocket = context.socket(zmq.SUB)
244250
self.subSocket.setsockopt(zmq.SUBSCRIBE, b"")
245251
self.subSocket.bind(f"tcp://*:{subPort}")
246252
self.socketTasks.append(asyncio.create_task(self.onZMQReceivePUBMessage()))
247253

248-
repPort = self.config.zmqPorts.get("REP")
249254
if repPort:
250255
self.repSocket = context.socket(zmq.REP)
251256
self.repSocket.bind(f"tcp://*:{repPort}")

src/main/core/config.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Config:
2525
"internalApiHost",
2626
"test",
2727
"zmqPorts",
28+
"useAerich",
2829
)
2930

3031
def __init__(
@@ -41,6 +42,7 @@ def __init__(
4142
internalApiHost: str | None = None,
4243
test: bool = False,
4344
zmqPorts: dict[str, int] | None = None,
45+
useAerich: bool = False,
4446
):
4547
self.token = token
4648
self.defaultPrefix = defaultPrefix or ">"
@@ -54,18 +56,23 @@ def __init__(
5456
self.internalApiHost = internalApiHost or "127.0.0.1:2264"
5557
self.test = test
5658
self.zmqPorts = zmqPorts or {}
59+
self.useAerich = useAerich
5760

5861
@property
5962
def tortoiseConfig(self):
6063
mainModel = "main.core.db"
6164
if not self.test:
6265
mainModel = "src." + mainModel
6366

67+
models = [mainModel]
68+
if self.useAerich:
69+
models.append("aerich.models")
70+
6471
return self._tortoiseConfig or {
6572
"connections": {"default": self.databaseUrl},
6673
"apps": {
6774
"models": {
68-
"models": [mainModel, "aerich.models"],
75+
"models": models,
6976
"default_connection": "default",
7077
},
7178
},

src/main/core/context.py

+24-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
file, You can obtain one at http://mozilla.org/MPL/2.0/.
55
"""
66

7+
from __future__ import annotations
8+
79
import io
810
from contextlib import asynccontextmanager
911
from typing import Union
@@ -24,10 +26,6 @@ def __init__(self, **kwargs) -> None:
2426
def session(self) -> aiohttp.ClientSession:
2527
return self.bot.session
2628

27-
# @property
28-
# def db(self):
29-
# return self.bot.db
30-
3129
@property
3230
def cache(self):
3331
return self.bot.cache
@@ -62,12 +60,20 @@ async def safe_send_reply(self, content, *, escape_mentions=True, type="send", *
6260
kwargs["content"] = content
6361
return await action(**kwargs)
6462

65-
async def safe_send(self, content, *, escape_mentions=True, **kwargs):
63+
async def safe_send(self, content, *, escape_mentions: bool = True, **kwargs):
64+
# TODO: Deprecate
6665
return await self.safe_send_reply(content, escape_mentions=escape_mentions, type="send", **kwargs)
6766

68-
async def safe_reply(self, content, *, escape_mentions=True, **kwargs):
67+
async def safeSend(self, content, *, escapeMentions: bool = True, **kwargs):
68+
return await self.safe_send(content, escape_mentions=escapeMentions, **kwargs)
69+
70+
async def safe_reply(self, content, *, escape_mentions: bool = True, **kwargs):
71+
# TODO: Deprecate
6972
return await self.safe_send_reply(content, escape_mentions=escape_mentions, type="reply", **kwargs)
7073

74+
async def safeReply(self, content, *, escapeMentions: bool = True, **kwargs):
75+
return await self.safe_reply(content, escape_mentions=escapeMentions, **kwargs)
76+
7177
async def error(self, error_message: str = None, title: str = "Something went wrong!"):
7278
e = ZEmbed.error(title="ERROR" + (f": {title}" if title else ""))
7379
if error_message is not None:
@@ -119,8 +125,19 @@ def replied_reference(self):
119125
return None
120126

121127
@discord.utils.cached_property
122-
def guild(self):
128+
def guild(self) -> GuildWrapper | None:
123129
g = self.message.guild
124130
if g:
125131
return GuildWrapper(g, self.bot)
126132
return None
133+
134+
def requireGuild(self) -> GuildWrapper:
135+
"""
136+
Inspired by Android's requireActivity()
137+
138+
Should only be used if the command has guild only check
139+
"""
140+
g = self.guild
141+
if not g:
142+
raise commands.NoPrivateMessage
143+
return g

src/main/core/menus.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def __init__(
9292
timeout: float = 180.0,
9393
ownerOnly: bool = True,
9494
) -> None:
95-
owner: Union[discord.User, discord.Member] = ctx.author
95+
owner: discord.User | discord.Member = ctx.author
9696
super().__init__(owner, timeout=timeout)
9797
self.context = ctx
9898
self._message: Optional[discord.Message] = None

src/main/exts/events/events.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from discord.app_commands import AppCommandError
1919
from discord.ext import commands
2020

21-
import tse
21+
from src import tse
2222

2323
from ...core import errors
2424
from ...core.embed import ZEmbed

src/main/exts/fun/fun.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,15 @@ async def findseed(self, ctx, *, args: FindseedFlags = None):
185185
"Ping random member\n" 'Also known as "Discord\'s mistake"\n' "**Note**: Only available on April Fools (UTC)!"
186186
),
187187
)
188+
@commands.cooldown(1, 5, commands.BucketType.user)
189+
@commands.guild_only()
188190
@checks.isAprilFool()
189-
async def someone(self, ctx):
190-
await ctx.send(choice(ctx.guild.members).mention)
191+
async def someone(self, ctx: Context):
192+
allowPingGuilds = (793642143243173888,)
193+
allowedMentions = discord.AllowedMentions.none()
194+
if ctx.requireGuild().id in allowPingGuilds:
195+
allowedMentions = discord.AllowedMentions(users=True)
196+
await ctx.send(choice(ctx.requireGuild().members).mention, allowed_mentions=allowedMentions)
191197

192198
@commands.hybrid_command(
193199
usage="(status code)",
@@ -317,7 +323,7 @@ async def flip(self, ctx):
317323
"**Support optional size**: d4, d8, d10, d00, d12, d20"
318324
),
319325
usage="[dice size] (number of dice)",
320-
extras=dict(example=("roll 5", "roll d20", "role d00 4")),
326+
extras=dict(example=("roll 5", "roll d20", "roll d00 4")),
321327
)
322328
@commands.cooldown(1, 5, type=commands.BucketType.user)
323329
async def roll(self, ctx, *args):

src/main/exts/info/info.py

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from ...utils import pillow
2222
from ...utils.api.openweather import CityNotFound, OpenWeatherAPI
2323
from ...utils.format import formatDiscordDT, renderBar
24-
from ...utils.infoQuote import * # noqa: F403
2524
from ...utils.other import authorOrReferenced, utcnow
2625

2726

0 commit comments

Comments
 (0)