Phibonacci / Total-Immersive-Chat-System

A Project Zomboid chat mod
0 stars 0 forks source link

[bug] Discord communication #2

Open Deide opened 5 days ago

Deide commented 5 days ago

I've enabled syncing with General in the sandbox settings. Before installing this mod, Discord integration worked (albeit with the duplication bug when the server was up for a certain amount of time).

I get this in the log when sending a message from Discord, and nothing turns up in game:

[TICS]  TICS error: failed to remove discord message prefix for message: "Message from Discord"

And when I send a message in /general in game, the message goes through to Discord, but the console records errors:

-------------------------------------------------------------
attempted index: message of non-table: null

-----------------------------------------
STACK TRACE
-----------------------------------------
function: DiscordMessage -- file: ClientRecv.lua line # 25 | MOD: Total Immersive Chat System
function: OnServerCommand -- file: ClientRecv.lua line # 190 | MOD: Total Immersive Chat System

ERROR: General     , 1732070212301> 418,191,103> ExceptionLogger.logException> Exception thrown java.lang.RuntimeException: attempted index: message of non-table: null at KahluaThread.tableget line:1689.
ERROR: General     , 1732070212302> 418,191,103> DebugLogStream.printException> Stack trace:
java.lang.RuntimeException: attempted index: message of non-table: null
    at se.krka.kahlua.vm.KahluaThread.tableget(KahluaThread.java:1689)
    at se.krka.kahlua.vm.KahluaThread.luaMainloop(KahluaThread.java:492)
    at se.krka.kahlua.vm.KahluaThread.call(KahluaThread.java:163)
    at se.krka.kahlua.vm.KahluaThread.pcall(KahluaThread.java:1980)
    at se.krka.kahlua.vm.KahluaThread.pcallvoid(KahluaThread.java:1812)
    at se.krka.kahlua.integration.LuaCaller.pcallvoid(LuaCaller.java:66)
    at se.krka.kahlua.integration.LuaCaller.protectedCallVoid(LuaCaller.java:139)
    at zombie.Lua.Event.trigger(Event.java:64)
    at zombie.Lua.LuaEventManager.triggerEvent(LuaEventManager.java:173)
    at zombie.network.GameClient.receiveClientCommand(GameClient.java:1513)
    at zombie.network.PacketTypes$PacketType.onMainLoopHandlePacketInternal(PacketTypes.java:1028)
    at zombie.network.GameClient.mainLoopHandlePacketInternal(GameClient.java:644)
    at zombie.network.GameClient.mainLoopDealWithNetData(GameClient.java:621)
    at zombie.network.GameClient.update(GameClient.java:431)
    at zombie.GameWindow.logic(GameWindow.java:232)
    at zombie.core.profiling.AbstractPerformanceProfileProbe.invokeAndMeasure(AbstractPerformanceProfileProbe.java:71)
    at zombie.GameWindow.frameStep(GameWindow.java:765)
    at zombie.GameWindow.run_ez(GameWindow.java:681)
    at zombie.GameWindow.mainThread(GameWindow.java:495)
    at java.base/java.lang.Thread.run(Unknown Source)

This error is repeated dozens of times. Perhaps this is a work-in-progress feature? The mod page mentions it working with /all, but /all is now disabled in favour of /general.

Phibonacci commented 5 days ago

Thank you for your report this is definitely a bug and I'll fix it very soon (likely tomorrow).

As for /general instead of /all, I forgot I made that change when I wrote the description. However, after thinking about it, I agree it would be best to keep the /all command as most player will be expecting it. I'll see if I can keep both /general and /all.

Phibonacci commented 4 days ago

I identified the bug when typing in general chat and fixed it.

/general is back to being /all.

Deide commented 4 days ago

Nice! The second error is completely gone, but the first one remains (there is still no Discord -> Zomboid communication despite seeing it in the server console).

Client console:

[TICS]  TICS error: failed to remove discord message prefix for message: "Message from Discord"

Server console:

LOG  : Network> DISCORD: send message = "Message from Discord" for deide)
LOG  : General> Message 'ChatMessage{chat=General, author='deide', text='Message from Discord'}' was sent to player with id '0' of chat '0'
LOG  : General> New message 'ChatMessage{chat=General, author='deide', text='Message from Discord'}' was sent members of chat '0'
Deide commented 2 days ago

@Phibonacci A friendly ping just in case you didn't see this.

Phibonacci commented 1 day ago

Indeed I missed it. I'll try to reproduce it tomorrow.

If I remember correctly, when I tested it discord was always prefixing the message with an id. I'm removing this id before processing the message. I can easily make it optional but I would like to know what we did differently for your messages to be without that prefix.

Deide commented 1 day ago

I have no clue. Perhaps because I set the channel ID in the settings?

Phibonacci commented 1 day ago

I cannot reproduce it, I never get that error message.

Do you send messages with @bot_name message on Discord? As I understand it PZ bot is only sending messages prefixed by a HL. But maybe I'm wrong and you actually managed to send messages directly?

Deide commented 1 day ago

Aha, that was it. We've never had to mention the bot to get it working before. I tried mentioning it and it works just fine. I guess if you don't specify a channel, it needs to be mentioned?

Phibonacci commented 1 day ago

I tested it by specifying both the channel and the channel ID and I never could make it work without a @bot. The wiki mentions:

Once configured, the Discord bot will post all messages from the in-game /all channel to the specified Discord channel. Any Discord messages that ping the Discord bot via @ or reply will be posted to the in-game /all channel.

I'm going to remove the error and make removing the prefix optional.

If you figure out what you did to make it work without a @ ping to the bot it would be appreciated by many servers I'm sure.

Deide commented 1 day ago

I have no clue. I don't recall doing anything special. Below are the only settings I changed, and it's been working all year.

# Enables global text chat integration with a Discord channel
DiscordEnable=true

# Discord bot access token
DiscordToken=<snip>

# The Discord channel name. (Try the separate channel ID option if having difficulties)
DiscordChannel=zomboid

# The Discord channel ID. (Use if having difficulties with Discord channel name option)
DiscordChannelID=<snip>

I was going to suggest that it has something to do with setting both the channel and channelID at the same time, but you even say that didn't work for you. Bizarre!

And I didn't do anything special with the bot, either. I gave it an avatar and changed its name.