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

✨ 使用正则过滤rcon传来的颜色字符 #116

Merged
merged 9 commits into from
Aug 24, 2024
29 changes: 0 additions & 29 deletions .github/workflows/push_pypi.yml

This file was deleted.

72 changes: 72 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Publish to PyPI And Release

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize]

permissions:
contents: write
env:
GH_TOKEN: ${{ github.token }}
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python -
poetry config pypi-token.pypi ${{ env.PYPI_API_TOKEN }}

- name: Get version from pyproject.toml
id: get_version
run: |
VERSION=$(poetry version -s)
echo "VERSION=$VERSION" >> $GITHUB_ENV

- name: Install dependencies
run: poetry install --no-root --no-dev

- name: Build and publish
if: github.event_name == 'push'
run: poetry publish --build

- name: Check if Release exists
id: check-release
run: |
# Check if the release exists
RESPONSE=$(gh release view v${{ env.VERSION }} -R ${{ github.repository }} 2>&1 || true)
if echo "$RESPONSE" | grep -q "Not Found"; then
echo "Release v${{ env.VERSION }} does not exist. Skipping deletion."
echo "RELEASE_EXISTS=false" >> $GITHUB_ENV
else
echo "Release v${{ env.VERSION }} exists."
echo "RELEASE_EXISTS=true" >> $GITHUB_ENV
fi

- name: Delete Release if exists
run: |
# Try to delete the release and handle errors gracefully
set +e
gh release delete v${{ env.VERSION }} -R ${{ github.repository }} -y --cleanup-tag
if [ $? -eq 0 ]; then
echo "Release v${{ env.VERSION }} deleted successfully."
else
echo "Failed to delete release v${{ env.VERSION }}. It might not exist or there might be another issue."
fi

- name: Create Release with generate note
if: github.event_name == 'push'
run: gh release create v${{ env.VERSION }} --generate-notes
2 changes: 2 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ jobs:

- name: Run Ruff Lint
uses: chartboost/ruff-action@v1
with:
args: check --fix .
13 changes: 7 additions & 6 deletions nonebot_plugin_mcqq/qq_msg.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Union

from nonebot.adapters import Message
Expand All @@ -7,7 +8,7 @@
from nonebot.adapters.qq import Bot as QQBot
from nonebot.internal.matcher import Matcher
from nonebot.adapters.onebot.v11 import Bot as OneBot
from mcqq_tool.rule import all_msg_rule, permission_check
from mcqq_tool.rule import all_msg_rule, permission_check, all_cmd_rule
from nonebot.adapters.qq import GuildMessageEvent as QQGuildMessageEvent
from nonebot_plugin_guild_patch import GuildMessageEvent as OneBotGuildMessageEvent
from nonebot.adapters.onebot.v11 import GroupMessageEvent as OneBotGroupMessageEvent
Expand All @@ -19,13 +20,13 @@
send_action_bar_to_target_server,
)

on_qq_msg = on_message(priority=5, rule=all_msg_rule)
on_qq_msg = on_message(priority=99, rule=all_msg_rule)

on_qq_cmd = on_command("minecraft_command", rule=all_msg_rule, aliases={"mcc"}, priority=4, block=True)
on_qq_cmd = on_command("minecraft_command", rule=all_cmd_rule, aliases={"mcc"}, priority=98)

on_qq_send_title_cmd = on_command("send_title", rule=all_msg_rule, aliases={"mcst"}, priority=4, block=True)
on_qq_send_title_cmd = on_command("send_title", rule=all_cmd_rule, aliases={"mcst"}, priority=98)

on_qq_action_bar_cmd = on_command("action_bar", rule=all_msg_rule, aliases={"mca"}, priority=4, block=True)
on_qq_action_bar_cmd = on_command("action_bar", rule=all_cmd_rule, aliases={"mca"}, priority=98)


@on_qq_msg.handle()
Expand Down Expand Up @@ -65,7 +66,7 @@ async def handle_qq_group_cmd(
await permission_check(matcher=matcher, bot=bot, event=event)

temp_result = await send_command_to_target_server(matcher=matcher, bot=bot, event=event, command=cmd)

temp_result = re.sub(r'§.', '', temp_result)
await on_qq_cmd.finish(temp_result)
else:
await on_qq_cmd.finish("你没有输入命令")
Expand Down
Loading