|
11 | 11 | broadcast,
|
12 | 12 | get_character_agent_for_name,
|
13 | 13 | get_current_world,
|
| 14 | + get_game_config, |
14 | 15 | set_character_agent,
|
15 | 16 | subscribe,
|
16 | 17 | )
|
17 |
| -from taleweave.models.config import DEFAULT_CONFIG, DiscordBotConfig |
| 18 | +from taleweave.models.config import DiscordBotConfig |
18 | 19 | from taleweave.models.event import (
|
19 | 20 | ActionEvent,
|
20 | 21 | GameEvent,
|
|
38 | 39 |
|
39 | 40 | logger = getLogger(__name__)
|
40 | 41 | client = None
|
41 |
| -bot_config: DiscordBotConfig = DEFAULT_CONFIG.bot.discord |
42 | 42 |
|
43 | 43 | active_tasks = set()
|
44 | 44 | event_messages: Dict[int, str | GameEvent] = {}
|
@@ -78,29 +78,32 @@ async def on_message(self, message):
|
78 | 78 | if message.author == self.user:
|
79 | 79 | return
|
80 | 80 |
|
| 81 | + config = get_game_config() |
81 | 82 | author = message.author
|
82 | 83 | channel = message.channel
|
83 | 84 | user_name = author.name # include nick
|
84 | 85 |
|
85 | 86 | if message.content.startswith(
|
86 |
| - bot_config.command_prefix + bot_config.name_command |
| 87 | + config.bot.discord.command_prefix + config.bot.discord.name_command |
87 | 88 | ):
|
88 | 89 | world = get_current_world()
|
89 | 90 | if world:
|
90 | 91 | world_message = format_prompt(
|
91 |
| - "discord_world_active", bot_name=bot_config.name_title, world=world |
| 92 | + "discord_world_active", |
| 93 | + bot_name=config.bot.discord.name_title, |
| 94 | + world=world, |
92 | 95 | )
|
93 | 96 | else:
|
94 | 97 | world_message = format_prompt(
|
95 |
| - "discord_world_none", bot_name=bot_config.name_title |
| 98 | + "discord_world_none", bot_name=config.bot.discord.name_title |
96 | 99 | )
|
97 | 100 |
|
98 | 101 | await message.channel.send(world_message)
|
99 | 102 | return
|
100 | 103 |
|
101 | 104 | if message.content.startswith("!help"):
|
102 | 105 | await message.channel.send(
|
103 |
| - format_prompt("discord_help", bot_name=bot_config.name_command) |
| 106 | + format_prompt("discord_help", bot_name=config.bot.discord.name_command) |
104 | 107 | )
|
105 | 108 | return
|
106 | 109 |
|
@@ -172,14 +175,11 @@ def prompt_player(event: PromptEvent):
|
172 | 175 |
|
173 | 176 |
|
174 | 177 | def launch_bot(config: DiscordBotConfig):
|
175 |
| - global bot_config |
176 | 178 | global client
|
177 | 179 |
|
178 |
| - bot_config = config |
179 |
| - |
180 | 180 | # message contents need to be enabled for multi-server bots
|
181 | 181 | intents = Intents.default()
|
182 |
| - if bot_config.content_intent: |
| 182 | + if config.content_intent: |
183 | 183 | intents.message_content = True
|
184 | 184 |
|
185 | 185 | client = AdventureClient(intents=intents)
|
@@ -246,12 +246,14 @@ def get_active_channels():
|
246 | 246 | if not client:
|
247 | 247 | return []
|
248 | 248 |
|
| 249 | + config = get_game_config() |
| 250 | + |
249 | 251 | # return client.private_channels
|
250 | 252 | return [
|
251 | 253 | channel
|
252 | 254 | for guild in client.guilds
|
253 | 255 | for channel in guild.text_channels
|
254 |
| - if channel.name in bot_config.channels |
| 256 | + if channel.name in config.bot.discord.channels |
255 | 257 | ]
|
256 | 258 |
|
257 | 259 |
|
|
0 commit comments