summaryrefslogtreecommitdiff
path: root/luamods/massping.lua
blob: ca700ec89c4085bc9cc1501e901107384f2785fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
return {
    name = "massping",
    delay_sec = 5,
    options = {},
    subcommands = {},
    minimal_rights = "moderator",
    handle = function(request)
        chatters = twitch_get_chatters()

        m = ""

        if request.message ~= nil then
            m = request.message .. " ·"
        end

        base = "📣 " .. m .. " "
        userlines = { "" }
        index = 1

        max_line_length = 500

        for i = 1, #chatters, 1 do
            chatter = chatters[i]
            curmsg = userlines[index]
            x = "@" .. chatter.login

            if #base + #curmsg + 1 + #x >= max_line_length then
                index = index + 1
            end

            if index > #userlines then
                table.insert(userlines, x)
            else
                userlines[index] = curmsg .. " " .. x
            end
        end

        msgs = {}

        for i = 1, #userlines, 1 do
            table.insert(msgs, base .. userlines[i])
        end

        return msgs
    end
}