If you want to use python and hackmud's chat API then you can use this tutorial! The hackmud_chat library is the base of this tutorial so please check out chalios' github: `3https://github.com/chalios/hackmud_chat_py`
Unfortunately it's written in python 2 so all of you who wants to use python 3 it wouldn't work. I'll also show you a quick example of doing a python script which sends a quick message in a specific channel.
So the slightly rewritten hackmud chat API is available on my github: `3https://github.com/Wrench56/hackmud`
As you can see, you need your chat_token which is a bit tricky to get. Here is a tutorial which will describe how to get a token and also how the chat API works: `3https://www.hackmud.com/forums/general_discussion/chat_api_documentation
Thanks for the tutorial mogery!
After you get your token, you can start scripting in python. You need to download both hackmud.py and hackmud_chat.py from my github. 'utlis.py' is optional but I will use it in this tutorial. Also main.py is optional but I highly recommend you to use it as a start.
Basically my scripts is made so that it could be run easily by linux crons. So each "advertise board" are separated in different scripts that can be run by different crons. If you don't want to use this system for some reason there is an example file in chalios' repo.
So the following script does the main part:
PATH = os.getcwd()
`5with` open(os.path.join(PATH, 'debug.log'), 'a', encoding='utf-8') `5as` file:
now = datetime.datetime.now()
time = now.strftime("[%Y-%m-%d %H:%M:%S]")
file.write(time + ' - ' + str(msg) + '\n')
user, channel, msg = func()
`5if` isinstance(channel, list):
`5for` c in channel:
acct = hackmud_chat.Account(token='YourToken')
user = acct.get_user('YourUsername')
`5return` acct, user
You can see the script is built out of 3 functions:
- The first is only a debug function (I pretty much just attached it to the script)
- The second function: send is a decorator
- The third one is the init which you will use at the start of your main script
The second function is a bit interesting. You see it has an arg called func which will be the function in the main file. The function from the main file should return three objects: a user object, a channel and a message. The channel can be either a single string or a list of channels. Unfortunately you can't join chats with the chat API so you have to join them manually in hackmud.
The main file looks like:
`5from` utils `5import` debug, send, init
acct, user = init()
`5return` user, "5P4M", "`2Pls` ignore this message!"
As you can see, it's very short and you don't need to do much. There should be a function which is called by the decorator `3@send`. The function must also return the three objects I mentioned earlier: the user, the channel (or list of channels) and the message! The init is used to get the user and account. This is the program you need to write to make an advertisement :).
So to make a linux cron you need to edit the crontab. If you are not familiar with crons I recommend you reading this guide: `3https://www.adminschoice.com/crontab-quick-reference`.
In order to edit the crontab you need to use: `0crontab -e` (-e is the arg for editing). Then you need to write your cron. My test_cron looked something like this:
`00 * * * * python3 /home/user/hackmud/main.py`
This runs the cron every 0th minutes of any hours. Of course, you need to change the path for your script but that's it. If this is done leave the editor and you are good to go :)
I hope I could help you!
Special thanks to:
@dtr[-], @Fayti1703[slyware], @ghamb[+], @matr1x[%] and to @mogery@xc