Welcome to Open Carnage

A resource for Halo Custom Edition and MCC modding, with unique means of rewarding content creation and support. Have a wander to see why we're worth the time! - EST. 2012

Chalwk

Halo 1 Discord Bot

Ladies and gentleman, let me introduce the star of the show: A fully integrated Discord Bot for SAPP Servers.

For full project details and installation instructions please see THIS PAGE.

If you need help installing on Linux (or Windows, for that matter), DM me on discord: Chalwk#9284

 

~edit

 

Updated on 15/02/2021 @ 22:17 PM NZST

  • Fixed bug causing inbound & outbound messages not to send to respective destinations.
  • Updated file documentation in settings.lua

Updated on 14/02/2021 @ 16:48 PM NZST

  • Fixed bug causing Discord.lua not to load
Edited by Chalwk
Tucker933, Enclusion, aLTis and 1 other like this

Add me on discord: Chalwk#9284

Share this post


Link to post
Share on other sites

Tiddy-bits:

Good work! I haven't read the whole release page yet so sorry if this is covered but is it possible to use webhooks for those who don't need a full bot but just want to post to a channel?

Share this post


Link to post
Share on other sites
12 minutes ago, Enclusion said:

Good work! I haven't read the whole release page yet so sorry if this is covered but is it possible to use webhooks for those who don't need a full bot but just want to post to a channel?

 

Yes, it is.

See the following docs: webhooks and D-API W/Hooks
For additional support I recommend joining the Discordia discord server: https://discord.gg/discord-api

Edited by Chalwk
Enclusion likes this

Add me on discord: Chalwk#9284

Share this post


Link to post
Share on other sites
On 2/14/2021 at 3:26 PM, Enclusion said:

Good work! I haven't read the whole release page yet so sorry if this is covered but is it possible to use webhooks for those who don't need a full bot but just want to post to a channel?

 

Webhooks use an array of embed objects called embeds.
Here is a functional example of a practical webhook fetch using embeds.

local function WhoWon()
    local str = "No Winner"
    local r_score = get_var(0, "$redscore")
    local b_score = get_var(0, "$bluescore")
    if (r_score > b_score) then
        str = "Red Team won!"
    elseif (b_score > r_score) then
        str = "Blue Team won!"
    elseif (b_score == r_score) then
        str = "IT WAS A TIE!"
    end
    return str
end

-- Note that you don't need to coroutine-wrap if you're executing the webhook in a discordia event since they're already in a coroutine
-- Make a GET request to your Webhook URL and fetch the ID and Token from it using JSON.
client._api:executeWebhook(id, token, {
    embeds = {
        { title = "Game Over", description = WhoWon() },
        { title = "New Game Started", description = get_var(0, "$map") .. " - " .. get_var(0, "$mode") } }
})

 

Edited by Chalwk
Enclusion likes this

Add me on discord: Chalwk#9284

Share this post


Link to post
Share on other sites

I am rather annoyed because I really wanted to implement a function that periodically updates a defined channel's topic with a live player count. 
For example 1/5000 players online | 1000 unique players ever joined | Server online for 2130 minutes | Last update: Tue, 16. Feb 2021 09:21:44 NZDT

 

It turns out that the Discord API has a hardcoded rate limit for channel name and topic updates of 2 per 10 minutes. This time frame is too long to make this functionality practical.

So, instead of a live player count, I could instead implement something like a MOTD, or output the current MVP of the day. Thoughts?

Enclusion likes this

Add me on discord: Chalwk#9284

Share this post


Link to post
Share on other sites

That's really lame. I know Discord's rate limits are a pain; we hardly deal with their dynamic limit for the Discord web viewer on the sidebar ..so it's often 30 minutes behind because we got temp blocked for trying to refresh every 5 or 10 minutes.

 

That rant over.. I'd personally prefer seeing MVP of the day up there. Small bragging right for some people and thus incentive for the server. I've never seen a server with a useful MoTD.

Chalwk and Enclusion like this

Oddly, this is familiar to you... as if from an old dream.  

splashdown.png

Guide to Balanced Gameplay

Share this post


Link to post
Share on other sites

A handful of bugs have been reported since releasing this project and will be fixed in an upcoming release so stay tuned.

 

Notable issues:

  • Inbound text messages from Discord occasionally fail to reach their destination (the halo server).
  • Names containing certain special characters can result in the client returning an Error 400 message.
Edited by Chalwk
mouseboyx, Tucker933 and Enclusion like this

Add me on discord: Chalwk#9284

Share this post


Link to post
Share on other sites
On 2/20/2021 at 2:09 PM, Chalwk said:

A handful of bugs have been reported since releasing this project and will be fixed in an upcoming release so stay tuned.

 

Notable issues:

  • Inbound text messages from Discord occasionally fail to reach their destination (the halo server).
  • Names containing certain special characters can result in the client returning an Error 400 message.

I was having issues with halo names with special characters for the web stats.  I've used these two lua functions, I can't remember where I found them, probably stackoverflow.

function encodeChar(chr)
	return string.format("%%%X",string.byte(chr))
end
 
function encodeString(str)
	local output, t = string.gsub(str,"[^%w]",encodeChar)
	return output
end

It works without a hitch when encoding something to be used in a query string like "http://mouseboyx.xyz/halo-stats/halo.php?exampleName="..encodeString(nameWithSpecialChars)

Discordia is already doing a url encode for making an http get request, but I was looking at the discordia dependencies and how it makes http post requests to send messages to discord.  I couldn't find whether it was actually url encoding post data that is sent out, so it may be worth checking out.  It definitely is doing a json encode though, that I know for sure.  If discordia already is url encoding post requests then using this function might be even worse because it will be double encoded and might produce some strange effects.

 

Edit:

Nevermind disregard this post I thought that the post request was being sent as "application/x-www-form-urlencoded" but it's being sent as "Content-Type: application/json" which work differently.

Edited by mouseboyx
Disregard

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.