Below is code to create a Discord Poker Bot (Webhook) for your poker site that can do many things using the callback system. In my last "How To" I posted I showed a crude example of how to create KO Tournaments with Player Bounties, so my first example below will be for a Discord Bot that post each KO into a channel on Discord which includes who was KO'd, who won the Bounty, the Tournament Name and the Bounty amount won.
KO Tourney Bounty Bot
Please note, this code is assuming you've already used the KO Tourney code in my previous post and the variables needed are already assigned. This is not my original code, I simply modified code I found on the internet to suit my purposes, credit goes to the original author.
Code: Select all
// send bot message to Discord
$message = "**$BountyPlayer Knocked Out $kodplayer from $TourneyName and won $bountyamt Chips!**";
$data = ['content' => $message];
$options = [
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => json_encode($data)
]
];
$context = stream_context_create($options);
$result = file_get_contents('https://discordapp.com/api/webhooks/YOUR WEBHOOK', false, $context);
Once you're in the Webhooks panel, click the big blue Create Webhook button. After that enter the name for your bot, upload an image if you want and then copy the Webhook URL at the bottom and paste into the code above where you see ...
$result = file_get_contents('https://discordapp.com/api/webhooks/YOUR WEBHOOK', false, $context);
Tourney Registration Open Bot
This code also will go into the callback.php file under this section ...
case "TourneyTimer":
fwrite($f,"Event = " . $event . "\n");
fwrite($f,"Name = " . $_POST["Name"] . "\n");
fwrite($f,"Number = " . $_POST["Number"] . "\n");
fwrite($f,"Timer = " . $_POST["Timer"] . "\n");
fwrite($f,"Count = " . $_POST["Count"] . "\n");
fwrite($f,"Time = " . $_POST["Time"] . "\n");
fwrite($f,"\n");
Code: Select all
$TourneyName = $_POST["Name"];
// This part is only shown as an example and only necessary if you want to limit which tourneys post via the bot
$params = array("Command" => "TournamentsGet", "Name" => $TourneyName);
$api = Poker_API($params);
$result = $api -> Result;
// limit by prizebonus
$prizepool = $api -> PrizeBonus;
// limit by currency
$currency = $api -> PrimaryCurrency;
if (($TourneyStart == "RegOpens") && ($currency == "Yes" || ($currency == "No" && $prizepool > 499))) {
// send bot message
$message = "**$TourneyName Tourney Registration is Open!**";
$data = ['content' => $message];
$options = [
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => json_encode($data)
]
];
$context = stream_context_create($options);
$result = file_get_contents('https://discordapp.com/api/webhooks/YOUR WEBHOOK', false, $context);
// ADDED BONUS : send message to poker lobby
$params = array("Command" => "SystemLobbyMessage", "Message" => "$TourneyName Tournament registration is open!");
$api = Poker_API($params);
$result = $api -> Result;
}
Simplified Tourney Registration Open Bot
Code: Select all
$TourneyName = $_POST["Name"];
// send bot message
$message = "**$TourneyName Tourney Registration is Open!**";
$data = ['content' => $message];
$options = [
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => json_encode($data)
]
];
$context = stream_context_create($options);
$result = file_get_contents('https://discordapp.com/api/webhooks/YOUR WEBHOOK', false, $context);
Using this code and a little modification you should be able to copypasta it anywhere in your callback.php file sections to do many things with it and either really annoy everyone in your Discord server or provide some useful information!
Hopefully I haven't missed anything and I hope you find this useful! If you are a Developer and you see that I've done something completely wrong or in a naive way that could be better, feel free to correct me ... I need to learn!