Skip to content

Commit

Permalink
chore: config for discord
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Feb 2, 2025
1 parent 21f16ec commit 5381e09
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
28 changes: 28 additions & 0 deletions pkg/core/migrations/m024_discord_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import annotations

from .. import migration


@migration.migration_class("discord-config", 24)
class DiscordConfigMigration(migration.Migration):
"""迁移"""

async def need_migrate(self) -> bool:
"""判断当前环境是否需要运行此迁移"""

for adapter in self.ap.platform_cfg.data['platform-adapters']:
if adapter['adapter'] == 'discord':
return False

return True

async def run(self):
"""执行迁移"""
self.ap.platform_cfg.data['platform-adapters'].append({
"adapter": "discord",
"enable": False,
"client_id": "1234567890",
"token": "XXXXXXXXXX"
})

await self.ap.platform_cfg.dump_config()
2 changes: 1 addition & 1 deletion pkg/core/stages/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ..migrations import m005_deepseek_cfg_completion, m006_vision_config, m007_qcg_center_url, m008_ad_fixwin_config_migrate, m009_msg_truncator_cfg
from ..migrations import m010_ollama_requester_config, m011_command_prefix_config, m012_runner_config, m013_http_api_config, m014_force_delay_config
from ..migrations import m015_gitee_ai_config, m016_dify_service_api, m017_dify_api_timeout_params, m018_xai_config, m019_zhipuai_config
from ..migrations import m020_wecom_config, m021_lark_config, m022_lmstudio_config, m023_siliconflow_config
from ..migrations import m020_wecom_config, m021_lark_config, m022_lmstudio_config, m023_siliconflow_config, m024_discord_config


@stage.stage_class("MigrationStage")
Expand Down
8 changes: 7 additions & 1 deletion pkg/platform/sources/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import base64
import uuid
import json
import os
import datetime

import aiohttp
Expand Down Expand Up @@ -201,7 +202,12 @@ async def on_message(self: discord.Client, message: discord.Message):
intents = discord.Intents.default()
intents.message_content = True

self.bot = MyClient(intents=intents, proxy=self.config["proxy"])
args = {}

if os.getenv("http_proxy"):
args["proxy"] = os.getenv("http_proxy")

self.bot = MyClient(intents=intents, **args)

async def send_message(
self, target_type: str, target_id: str, message: platform_message.MessageChain
Expand Down
6 changes: 6 additions & 0 deletions templates/platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
"app_id": "cli_abcdefgh",
"app_secret": "XXXXXXXXXX",
"bot_name": "LangBot"
},
{
"adapter": "discord",
"enable": true,
"client_id": "1234567890",
"token": "XXXXXXXXXX"
}
],
"track-function-calls": true,
Expand Down
31 changes: 31 additions & 0 deletions templates/schema/platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,37 @@
"description": "飞书的bot_name"
}
}
},
{
"title": "Discord 适配器",
"description": "用于接入 Discord",
"properties": {
"adapter": {
"type": "string",
"const": "discord"
},
"enable": {
"type": "boolean",
"default": false,
"description": "是否启用此适配器",
"layout": {
"comp": "switch",
"props": {
"color": "primary"
}
}
},
"client_id": {
"type": "string",
"default": "",
"description": "Discord 的 client_id"
},
"token": {
"type": "string",
"default": "",
"description": "Discord 的 token"
}
}
}
]
}
Expand Down

0 comments on commit 5381e09

Please sign in to comment.