mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
chore: config for discord
This commit is contained in:
28
pkg/core/migrations/m024_discord_config.py
Normal file
28
pkg/core/migrations/m024_discord_config.py
Normal file
@@ -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()
|
||||
@@ -8,7 +8,7 @@ from ..migrations import m001_sensitive_word_migration, m002_openai_config_migra
|
||||
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")
|
||||
|
||||
@@ -10,6 +10,7 @@ import re
|
||||
import base64
|
||||
import uuid
|
||||
import json
|
||||
import os
|
||||
import datetime
|
||||
|
||||
import aiohttp
|
||||
@@ -201,7 +202,12 @@ class DiscordMessageSourceAdapter(adapter.MessageSourceAdapter):
|
||||
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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user