--!strict -- Owner & Creator: Jievy Tabiolo ยท Jievienne AI -- Chonkibee for Roblox: post to Chonkibee channels, answer slash commands, and show what players are playing. -- -- HOW TO USE -- 1. Put this ModuleScript in ServerScriptService (or ServerStorage). NEVER in ReplicatedStorage: -- anything there is copied to every player's device, and your webhook link / bot token is a secret. -- 2. Turn on Game Settings โ†’ Security โ†’ Allow HTTP Requests. -- 3. Keep secrets out of your code. Store them with the Secrets Store (HttpService:GetSecret) where available, -- or at least in a server-only place. -- -- local Chonkibee = require(game.ServerScriptService.Chonkibee) -- local feed = Chonkibee.webhook("https://chonkibee.jievienne.com/api/webhooks/ID/SECRET") -- feed:post("๐Ÿ† Rae won the round!", { title = "Score: 12,480", color = 0xE8913A }) -- -- local bot = Chonkibee.bot("APP_ID.SECRET") -- bot:commands({ { name = "stats", description = "Show a player's stats" } }) -- bot:onCommand("CHANNEL_ID", "stats", function(cmd) return "Stats for " .. cmd.args .. ": 12 wins" end) -- bot:setPlaying("CHONKIBEE_USER_ID", "Ranked match ยท Desert map", 20) local HttpService = game:GetService("HttpService") local RunService = game:GetService("RunService") assert(RunService:IsServer(), "Chonkibee must only be used from server scripts. Never put it where players can see it.") local OWNER = "Jievy Tabiolo" local BASE = "https://chonkibee.jievienne.com" local USER_AGENT = "Chonkibee-Roblox/2 (" .. OWNER:sub(1, 0) .. "roblox)" export type Embed = { title: string?, description: string?, url: string?, color: number?, fields: { { name: string, value: string, inline: boolean? } }?, footer: string? } export type Command = { id: number, name: string, args: string, authorId: string, authorName: string, channelId: string } -- ---------- a small send queue: stays under Chonkibee's 30 messages a minute, retries politely ---------- local function newBucket(perMinute: number) return { tokens = perMinute, max = perMinute, rate = perMinute / 60, last = os.clock() } end local function take(b: any) while true do local now = os.clock() b.tokens = math.min(b.max, b.tokens + (now - b.last) * b.rate) b.last = now if b.tokens >= 1 then b.tokens -= 1 return end task.wait((1 - b.tokens) / b.rate) end end local function request(method: string, url: string, headers: { [string]: string }, body: any?): (boolean, any) headers["Content-Type"] = "application/json" headers["User-Agent"] = USER_AGENT for attempt = 1, 4 do local ok, res = pcall(HttpService.RequestAsync, HttpService, { Url = url, Method = method, Headers = headers, Body = body ~= nil and HttpService:JSONEncode(body) or nil, }) if ok and res.StatusCode >= 200 and res.StatusCode < 300 then local decoded = nil pcall(function() decoded = HttpService:JSONDecode(res.Body) end) return true, decoded end local status = ok and res.StatusCode or 0 -- 429 = slow down, 5xx/0 = network trouble: wait and retry. Anything else is a real error: stop. if status ~= 429 and status < 500 and status ~= 0 then warn("[Chonkibee] " .. method .. " failed (" .. status .. "): " .. (ok and res.Body or tostring(res))) return false, nil end task.wait(2 ^ attempt) end warn("[Chonkibee] gave up after retries: " .. url) return false, nil end local function text(v: unknown, max: number): string? if typeof(v) ~= "string" then return nil end return (v :: string):sub(1, max) end local function cleanEmbed(e: any): Embed? if typeof(e) ~= "table" then return nil end local color = e.color if typeof(color) ~= "number" or color ~= color then color = nil end return { title = text(e.title, 256), description = text(e.description, 2000), url = text(e.url, 300), color = color, fields = e.fields, footer = text(e.footer, 200) } end local Chonkibee = {} -- ---------- webhooks: the simplest way to post ---------- local Webhook = {} Webhook.__index = Webhook function Chonkibee.webhook(url: string) assert(typeof(url) == "string" and url:match("^https://[%w%.%-]+/api/webhooks/%x+/%x+$"), "Chonkibee.webhook needs the full webhook link") return setmetatable({ url = url, bucket = newBucket(28) }, Webhook) end -- feed:post(content, embed?, username?) โ†’ runs in the background, never blocks your game function Webhook:post(content: string?, embed: Embed?, username: string?) local body = { content = text(content, 2000), username = text(username, 40), embeds = embed and { cleanEmbed(embed) } or nil } task.spawn(function() take(self.bucket) request("POST", self.url, {}, body) end) end -- feed:poll("Which map next?", { "Desert", "Snow" }) function Webhook:poll(question: string, options: { string }) task.spawn(function() take(self.bucket) request("POST", self.url, {}, { poll = { question = text(question, 200), options = options } }) end) end -- ---------- bots: commands, replies and "playing now" ---------- local Bot = {} Bot.__index = Bot function Chonkibee.bot(tokenValue: string, base: string?) assert(typeof(tokenValue) == "string" and tokenValue:match("^%x+%.%x+$"), "Chonkibee.bot needs your bot token (APP_ID.SECRET)") return setmetatable({ auth = "Bot " .. tokenValue, base = (base or BASE) .. "/api/v1", bucket = newBucket(28), handlers = {}, polling = {} }, Bot) end function Bot:call(method: string, path: string, body: any?): (boolean, any) return request(method, self.base .. path, { Authorization = self.auth }, body) end -- bot:send(channelId, content, embed?, replyTo?) function Bot:send(channelId: string, content: string?, embed: Embed?, replyTo: number?) task.spawn(function() take(self.bucket) self:call("POST", "/channels/" .. channelId .. "/messages", { content = text(content, 2000), embeds = embed and { cleanEmbed(embed) } or nil, reply_to = replyTo }) end) end -- bot:commands({ { name = "stats", description = "..." } }) โ†’ shows up when people type / in Chonkibee function Bot:commands(list: { { name: string, description: string? } }) return self:call("PUT", "/commands", list) end -- bot:setPlaying(chonkiUserId, "Ranked match", minutes?) โ†’ shows "๐ŸŽฎ Ranked match" on their Chonkibee profile -- Only works for people in a server your bot is in, who allow game status. Pass "" to clear. function Bot:setPlaying(chonkiUserId: string, activity: string, minutes: number?) local m = minutes or 15 if m ~= m then m = 15 end task.spawn(function() self:call("POST", "/presence", { user_id = chonkiUserId, text = text(activity, 60) or "", minutes = math.clamp(math.floor(m), 1, 240) }) end) end -- bot:onCommand(channelId, "stats", function(cmd) return "reply text" end) -- Checks the channel every few seconds. Return a string (or nothing) from your function. function Bot:onCommand(channelId: string, name: string, fn: (Command) -> string?) self.handlers[channelId] = self.handlers[channelId] or {} self.handlers[channelId][name] = fn if self.polling[channelId] then return end self.polling[channelId] = true task.spawn(function() local after = 0 -- start from "now" so old commands are not answered again after a restart local ok, data = self:call("GET", "/channels/" .. channelId .. "/messages?limit=1") if ok and data and data.messages and data.messages[1] then after = data.messages[1].id end while self.polling[channelId] do local okPoll, page = self:call("GET", "/channels/" .. channelId .. "/messages?after=" .. after) if okPoll and page and page.messages then for _, m in page.messages do after = math.max(after, m.id) local c = m.command local handler = c and self.handlers[channelId][c.name] if handler then local cmd: Command = { id = m.id, name = c.name, args = c.args or "", authorId = m.author.id, authorName = m.author.name, channelId = channelId } local okRun, reply = pcall(handler, cmd) if okRun and typeof(reply) == "string" and reply ~= "" then self:send(channelId, reply, nil, m.id) elseif not okRun then warn("[Chonkibee] command /" .. c.name .. " failed: " .. tostring(reply)) end end end end task.wait(3) end end) end function Bot:stop(channelId: string) self.polling[channelId] = nil end -- Still reading? The owner of Chonkibee asks: do you wanna be my faithful followerr? -- If you followed all of this, you're genius enough to be one of Jievy Tabiolo's disciples. return Chonkibee