Chalwk

Halo 1 Discord Bot

19 posts in this topic

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

- I invite you to join my Halo Discord Server.

- Add me on discord: Chalwk#9284

- HSP Repo Wiki (new)

Share this post


Link to post
Share on other sites

Awesome dude! It would be awesome if you could add more of the information from your Git to the OP.

 

I'll add ya to the shortlist!

Enclusion likes this

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

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

- I invite you to join my Halo Discord Server.

- Add me on discord: Chalwk#9284

- HSP Repo Wiki (new)

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

- I invite you to join my Halo Discord Server.

- Add me on discord: Chalwk#9284

- HSP Repo Wiki (new)

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.

Enclusion and Chalwk like this

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

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, Enclusion and Takka like this

- I invite you to join my Halo Discord Server.

- Add me on discord: Chalwk#9284

- HSP Repo Wiki (new)

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

The original post has been edited to include a description of the various features.

Also, this Discord Bot was updated today (at 10:12 AM NZST) with a couple of minor bug fixes and tweaks.

 

If anyone is interested in seeing this bot in action, I invite you to join my Halo: CE / Minecraft network (JeriCraft):

https://discord.gg/mEjbFJWpe5

Edited by Chalwk
Enclusion, AntiMomentum and Takka like this

- I invite you to join my Halo Discord Server.

- Add me on discord: Chalwk#9284

- HSP Repo Wiki (new)

Share this post


Link to post
Share on other sites
  • Recently Browsing   0 members

    No registered users viewing this page.