HotaruBlaze / TES3MP_DiscordRelay

Discord Relay for TES3MP!
5 stars 2 forks source link

Add Discord ==> tes3mp chat support #1

Closed terabyte25 closed 5 years ago

terabyte25 commented 5 years ago

Yes, I know you mentioned this in the readme. I am only creating an issue because it's easier to keep track of it.

HotaruBlaze commented 5 years ago

@terabyte25 Do you mean Discord to tes3mp or tes3mp to Discord?

If tes3mp to discord their is a webhook branch you can use here

else if you mean discord to tes3mp, i am currently looking into possible solutions.

terabyte25 commented 5 years ago

Oh, sorry. I did my title wrong. Fixed.

Right now I am aware you're working on it, I'm only making this issue for reference.

terabyte25 commented 5 years ago

https://github.com/TES3MP-TeamFOSS/Scripts/tree/master/0.6.1/scripts/IrcBridge possibly helpful?

ghost commented 5 years ago

you give them over with a json. just read the json in UpdateTime() in serverCore?

terabyte25 commented 5 years ago

@Schnibbsel can you go more in depth?

HotaruBlaze commented 5 years ago

@Schnibbsel As much as yes that could be a solution, it is not a good one and i would like to avoid it.

Using json to handle this wouldn't work well as a bot currently cannot stay connected to receive messages from discord.

Doing a json would also provide a delay for discord -> tes3mp messages.

So even temporarily storing those messages in json would be pointless when u can send a message Directly

If u are implying using another bot to put discord messages into a json for tes3mp to read, its still very hacky and not a great solution.

HotaruBlaze commented 5 years ago

Im currently looking into having a "middleware" bot that would handle messages to and from discord and tes3mp, however implementing this on tes3mp side is harder than i initially thought.

This would work talk with tes3mp by running a basic http server as a script that would work as an api to get and send info, as well as server info.

However just simply doing this causes slowdown on tes3mp due to being one thread and having to "pause" serverlogic while u check or process, so it needs to be made to run without interrupting the servers own logic that we would hook into. (Looking into coroutines right now as a possible solution)

Doing it this way would give u alot more options u can do if correctly implemented.

ghost commented 5 years ago

maybe i learn something. and really out of intrest: this thing alrdy has been done and is working fine. why make so much thoughts about how the perfect solution would be? (i dont think you considering any real pratical issue outcome. you just making a lot of thoughts on an intellectual level about what the perfect programing solution would be.) while you sure know. the (only) best solution would be an integreation into the c++ code..

Shigbeard commented 5 years ago

While it is true that it would be far more optimal to develop a two-way relay solution in a language like C++ or C#... in reality that isn't a solution that's compatible with the project's goal. If you want to provide a plugin for servers to run to relay content between their server and their discord community, you need to be able to run it from the native language for custom addons or plugins.

There are several issues with requesting the channel messages as json data from the server. Yes, you don't need an open socket to discord in order to obtain them, you can just make a HTTP request... but you get no control in the amount of data you receive. You will always receive the most recent 50 messages, every time you request it. You have no idea if you have already displayed a message you are looping over in the json data. You spend a lot of time either looping over data you aren't going to use again, or trimming out data you've already used. And lastly you have no way of getting Discord to tell you when there's new data... you have to ask Discord for it yourself. So in order to even make it work, you need to request data every second, record messages you've already processed, trim out messages every time you request messages for messages you've already processed, and thats all before you even relay anything. And every second you are looping over 50 messages.

Overall it's a very VERY inefficient design, can result in high I/O and disk usage. It's better to make a solution that opens an asyncronous socket to Discord, where discord can then update the bot every time a message is sent, with only the relevant data as opposed to 50 messages, 49 of which will be complete garbage.

terabyte25 commented 5 years ago

Should this be changed in accordance to #3?

HotaruBlaze commented 5 years ago

@terabyte25 Nah, your fine, #3 is for new issues/features or that dont already have a base.

As we know the intention of this issue beforehand, i would say its not required.

You are freely allowed to change it in accordance of #3 if you wish

ghost commented 5 years ago

so.. why the anger? i am just a low level scripter. no experienced programer at all. never said that and never wanted to offend anyone. the question i asked above was honest and rly out of intrest.

there is a RCON BOT not only syncing ingame chat with discord but also offering possibility to send server commands. its running with discordia api. not implemented into tes3mp. you just run 2 processes.... luavit and tes3mp. it is rly basic and rly easy...

there is the IRC BOT terabyte linked + theres irc-discord syncs going around and there is the ECARLATE discord bot on python

all of those are running fine. nothing crashed or anything. no bugs been reported.

so i didnt want to offend anyone. i see this is more common around programers:

to want to make a lot of thoughts about the perfect solution within the limitations while there is no need for it.<< sorry if this sounded like an offend. i am just asking out ouf intrest. and hope to learn sth.

HotaruBlaze commented 5 years ago

there is a RCON BOT not only syncing ingame chat with discord but also offering possibility to send server commands.

I believe i have seen this however i cannot find the source code again for a reference, although i am curious how its implemented.

there is the IRC BOT terabyte linked

I have seen this before and looked through it, however unlike IRC however you have issues with keeping a discord connection as mentioned above by @Shigbeard


I would like to idealy be able to query more data from tes3mp than simply relay chat, so that would still require getting more data than simply say, reading console output or onPlayerSendMessage.

So, sure i could use discordia as another process, but my knowledge of lua is extremly basic unlike nodejs for example where i know the language alot more.

These would both do serve the same purpose, however most likely a nodejs version would be more modular and customizable due to knowledge alone. however it would still provide a http proxy that someone would easily replace the nodejs part with something else.

The current limitation is making the "client/server" on tes3mp's side to respond to requests (Planned via a HTTP REST API like system), Not the middleware (if ever used)

HotaruBlaze commented 5 years ago

If anyone is still looking for this, I just pushed a branch here

This uses an updated version of IrcBridge for tes3mp 0.7.0-alpha with matterbridge. Acting as a relay between discord and and tes3mp, with a simple IRC as middle-ware.

I would like to stress that this is not a simple drag and drop and requires some basic knowledge or googling skills.

For now I'm going to close this ticket finally, as this seems as close as i will currently be able to get.

I have not discovered any bugs or performance penalty on tes3mp.