//Option 1 is easy to explain and so I've done the write up for it now to go with the video recorder thread. Option 2 I'll write up later.

When you're running bots it's generally quite nice if you can be notified whenever your bots stops running, rather than having to manually check up on them to see what's up.

There's 2 main options for getting a notification whenever your script stops:
1) simply sending a notification from the script itself, on terminatation
2) maintaining a heartbeat connection and firing the notification whenever the script fails to tell the monitoring server it's alive. See: https://en.wikipedia.org/wiki/Heartbeat_(computing)
Option 1 is super quick & easy to implement but not as reliable. Option 2 is very reliable but not as quick & easy to implement.

Discord makes it pretty simple to send notifications via their webhooks, so I will be using discord notifications as the examples for this guide. These ideas appy across other mediums such as email, text msg, skype, slack, phone call playing a prerecorded message saying "beep boop your bot is down", etc. The implementations would however ofcourse be different.

In order to send a notification to yourself on discord via simba, you will need a discord webhook url.
Here's a video demonstration on how to get a discord webhook url https://streamable.com/m6x4f
Alternative source of video: https://cdn.discordapp.com/attachmen...1_01-47-28.mp4

Option 1. Sending a discord notification on terminate

You will need to be able to send a post request to the webhook url with the webhook JSON.
Here's one possible way to write a simba procedure to do that
Simba Code:
Procedure SendDiscordWebhook(WebhookURL, JSON: string);var  HTTPClient: Integer;begin  HTTPClient := InitializeHTTPClient(False);  PostHTTPPage(HTTPClient, WebhookURL, JSON);  FreeHTTPClient(HTTPClient);end;

Here's how you might use such a procedure in a script.
Simba Code:
const  DiscordWebhookURL = '';  DiscordWebhookJSON = '{"content" : "Text goes here"}';Procedure SendDiscordWebhook(WebhookURL, JSON: string);var  HTTPClient: Integer;begin  HTTPClient := InitializeHTTPClient(False);  PostHTTPPage(HTTPClient, WebhookURL, JSON);  FreeHTTPClient(HTTPClient);end;Procedure Terminator();begin  SendDiscordWebhook(DiscordWebhookURL, DiscordWebhookJSON);end;begin  AddOnTerminate('Terminator'); //whenever the script terminates [safely], the Terminator() procedure will be called    //rest of the scriptend.

Try it out. Just put that into code simba, add your webhook url to "DiscordWebhookURL", and run the code. You should see "Text goes here" submitted into your text channel.

More info on discord webhook JSON parameters can be found here (incase you want anything fancier than just simple text messages)
https://discordapp.com/developers/do...ources/webhook
and here
https://birdie0.github.io/discord-we...d_webhook.html

Option 2. Sending a discord notification from the monitoring server once your script stops messaging the server

//todo, later

Implementation for this is already created and tested, just gotta do the write up explaining how to repeat my steps. Implementation for the monitoring server will be in python (using flask).

2. Cool! Never thought about using webhooks. That's much easier than the route I went down. (made a python script which I packaged into a .exe to call from Simba)
Python Code:
import discordimport asyncioimport sysimport os.pathclient = discord.Client()@client.event@asyncio.coroutinedef on_ready():    yield from client.wait_until_ready()        channel = discord.Object(id=sys.argv[1])    if os.path.exists(sys.argv[3]):        yield from client.send_file(channel, sys.argv[3])    else:        yield from client.send_message(channel, sys.argv[3])            yield from client.logout()client.run(sys.argv[2])# discord_msg.exe "CHANNEL" "TOKEN" "MESSAGE / IMAGE PATH" # pyinstaller for exe

3. Ayy super cool! Can't wait to see your write up on the heartbeat one

4. Nice @acow;

I personally used push notifications (Pushover app) but this ends up being better since we have Discord on both PC and phone!

5. Registered User
Join Date
May 2019
Posts
6
Mentioned
0 Post(s)
Quoted
0 Post(s)
I use to push notification each time now this is super cool. Thanks for the information.

6. SRL Junior Member
Join Date
Nov 2010
Posts
305
Mentioned
0 Post(s)
Quoted
6 Post(s)
Hi and thank you @acow!

I changed it a bit for personal use (and perhaps easier to use)

Simba Code:
const DiscordWebhookURL := 'url';Procedure SendDiscordWebhook(JSON: string);var  HTTPClient: Integer;begin  HTTPClient := InitializeHTTPClient(False);  PostHTTPPage(HTTPClient, DiscordWebhookURL, '{"content" : "['+ FormatDateTime('tt', Time) + ']\n' + JSON + '"}'); //Just added current time  FreeHTTPClient(HTTPClient);end;

Usage
Simba Code:
SendDiscordWebhook(+'Not mining'); //Notice the '+' in front

Result
s8TR2WB.png

7. Hey guys.

I have tried doing the above examples without any luck.

Anyone mind telling me what I am doing wrong?
Not getting any data coming through on the channel at all.

Simba Code:
program new;const  DiscordWebhookURL = 'http://discordapp.com/api/webhooks/602319574863708171/gVoLTLYGghVdhz_XX-6sabstnvOtRdGyOhkhUhpUW0yG0O9TH_74SFgmxTlA99qnyaj8';  DiscordWebhookJSON = '{"content" : "Test"}';Procedure SendDiscordWebhook(WebhookURL, JSON: string);var  HTTPClient: Integer;begin  HTTPClient := InitializeHTTPClient(False);  writeln(HTTPClient);  PostHTTPPage(HTTPClient, WebhookURL, JSON);  writeln(GetHTTPPage(HTTPClient, DiscordWebhookURL));  FreeHTTPClient(HTTPClient);end;Procedure Terminator();begin  SendDiscordWebhook(DiscordWebhookURL, DiscordWebhookJSON);end;begin  AddOnTerminate('Terminator'); //whenever the script terminates [safely], the Terminator() procedure will be called  SendDiscordWebhook(DiscordWebhookURL, DiscordWebhookJSON);  //rest of the scriptend.

8. Originally Posted by Dan the man
Hey guys.

I have tried doing the above examples without any luck.

Anyone mind telling me what I am doing wrong?
Not getting any data coming through on the channel at all.
That's weird. I copy/pasted your code and just replaced the url with my own and it worked perfectly. Tried with your url and it failed. Maybe try to generate a new webhook url?

9. Originally Posted by Citrus
That's weird. I copy/pasted your code and just replaced the url with my own and it worked perfectly. Tried with your url and it failed. Maybe try to generate a new webhook url?
Yeah I tried that on a few different servers I made with the same result. Very unusual. Any other Discord settings I am not thinking of?

10. Originally Posted by Citrus
That's weird. I copy/pasted your code and just replaced the url with my own and it worked perfectly. Tried with your url and it failed. Maybe try to generate a new webhook url?
Would u mind sharing the url that worked for you?
Will allow me to eliminate my Simba client as an issue.

EDIT: If you are having the same issue as me, the problem was Simba 1.2. There is a bug that prevents it from sending the hook. Use Simba 1.3 or 1.1.
Last edited by Dan the man; 07-24-2019 at 01:14 AM.

11. Originally Posted by Dan the man
EDIT: If you are having the same issue as me, the problem was Simba 1.2. There is a bug that prevents it from sending the hook. Use Simba 1.3 or 1.1.
That's surprising since iirc only simba 1.2 was used for developing this and the video recorder. If you're using 1.2, the version by slacky is probably the one you should be using. https://github.com/slackydev/Simba/r...-fixes.x86.exe

if it works for 1.3, which it seems to, that's probably the way to go currently.

12. Just tested that version and it didnt work.

After ainstakingly removing the reliance on aerolib from my include, i have managed to move it to 1.3 and it works flawlessly