Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does the Discord Bot work? #2

Open
SoapySandwich opened this issue Jun 15, 2020 · 5 comments
Open

How does the Discord Bot work? #2

SoapySandwich opened this issue Jun 15, 2020 · 5 comments
Labels
info useful information

Comments

@SoapySandwich
Copy link

SoapySandwich commented Jun 15, 2020

I did connect this bot to my own discord server correctly , and i edited port limited from 1024 to 1010 then i added this ip 94.250.248.183:1010 to my.txt file for testing zCatch server info but write !servers give this msg "could not fetch any server infos." I tried add some other ip by !add ip:port manually but !servers get me same error. So i need to know what im wrong and what i must to do i did it for ddrace gametype that same error given. Notice : permission bot , read , write given to the discord bot.

@SoapySandwich SoapySandwich changed the title How it wirk exactly ? How it work exactly ? Jun 16, 2020
@jxsl13
Copy link
Owner

jxsl13 commented Jun 16, 2020

in the readme.md you see how the .env has to look like.
the .env file works the same with all my other Go projects.
it must be located in the same folder from which you start the bot.

./TeeworldsDiscordBotGo
./.env

./tools/./TeeworldsDiscordBotGo
./.env

when starting the program you also pass the file -f servers.txt that contains one ip:port pair per line.
servers.txt is updated if you execute the !save command.
with !add ip:port (sv_port!) you can add new servers to the list.
the allowed commands can be found here (click on the link):

switch command {

normal users can execute these commands:

"!h", "!help": show help screen for normal users
"!o <gametype>", "!online <gametype>": if there is no game type passed, the default game type is used as defined in the .env file with DEFAULT_GAMETYPE_FILTER
"!s", "!servers": shows a list of all servers that are currently held in the server list in memory. this also shows if specific servers cannot be checked anymore, because they are not running anymore or their ping is too bad to be pinged.

an admin user as defined with DISCORD_ADMIN can execute these commands:

"!add <ip:port>": add a new teeworlds server to the list of servers that are checked, when the !online command is executed
"!save": save all currently in memory held server addresses to the <-f servers.txt> file
"!delete <ip:port>": delete specific server that is exactly <ip:port> 
"!c", "!clean", "!clear": when executing !servers, you will see specific servers that cannot be reached anymore. !c removes those servers from the in-memory server list. if you want to save the remaining reachable servers to a file, you can execute !save afterwards. Keeping the server list clean helps fetching server data faster. if a server is not reachable, you will have to wait 500 milliseconds before the requests to the not reachable servers timeouts and after that you get your result in discord. if you have only reachable servers in your list, you will get the result after the slowest server answered the bot, most likely way faster than 500 milliseconds.

the bot fetches server data just in time. this means when executing !servers or !o or !online the bot sends a server info request to all the servers in the server list (in memory/servers.txt) and waits for their responses. after that the bot sends the server list in the discord channel where the !servers was executed.
the result is sorted by online players on the servers.

@jxsl13 jxsl13 added the info useful information label Jun 16, 2020
@jxsl13 jxsl13 pinned this issue Jun 16, 2020
@jxsl13 jxsl13 changed the title How it work exactly ? How does the Discord Bot work? Jun 16, 2020
@SoapySandwich
Copy link
Author

SoapySandwich commented Jun 17, 2020

Screenshot_۲۰۲۰۰۶۱۷-۱۰۳۲۵۸_Admin Hands
Screenshot_۲۰۲۰۰۶۱۷-۱۰۳۶۰۲_Admin Hands
Screenshot_۲۰۲۰۰۶۱۷-۱۱۵۶۵۵_Discord

Not worked , Seems master server not responding.

@SoapySandwich SoapySandwich reopened this Jun 17, 2020
@jxsl13
Copy link
Owner

jxsl13 commented Jun 17, 2020

can you find your servers if you look for them in Teeworlds? You need to use those IPs. 127.0.0.1 should not be used in this case. Use the external IP instead.

the bot does not communicate with the masterservers at all.

another problem might be that your discord bot has a rather bad connection to those servers.
if the delay between your discord bot and each of the servers in the list is worse than about 200 milliseconds, I would guess that you the connection will timeout before you can get any data from the servers.
you can tweak the timeout with SERVER_RESPONSE_TIMEOUT_MS=1000 in the .env file.

the server IPs and ports should be the ones that can be found in the Teeworlds server list (in game).
the port must explicitly correspond to the sv_port value in your Teeworlds server configuration.
Also the bot only supports 0.7.x Teeworlds servers. the version 0.6 is not supported.

@SoapySandwich
Copy link
Author

Ahh, Also the bot only supports 0.7.x Teeworlds servers. the version 0.6 is not supported. so this is the problem, is there any plan for 0.6 ?

@jxsl13
Copy link
Owner

jxsl13 commented Jun 17, 2020

no, 0.6 is kind of outdated. even tho there are still people playing there, I do not intend to support it, because it will eventually die.
status.tw supports 0.6 servers, but you would need to wrap their developer api in an own discord bot or extend this bot to use the status.tw api. https://status.tw has drawbacks in regard to the requested server info being outdated up to like 5 minutes or so, I'd guess.

Currently there is no such plan from my side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info useful information
Projects
None yet
Development

No branches or pull requests

2 participants