summaryrefslogtreecommitdiff
path: root/luamods/spam.lua
blob: ac5a70cf00bbb3c5c78aff98ece35d1831d62bad (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
local lines = {
    english = {
        ["no_message"] = "{sender.alias_name}: Message must be provided.",
    },
    russian = {
        ["no_message"] = "{sender.alias_name}: Сообщение должно быть предоставлено.",
    },
}

return {
    name = "spam",
    description = [[
> It is recommended to give the bot moderator rights in the chat room. This will speed up the sending of messages.

The `!spam` command gives users the ability to repeat a given message a certain number of times in a chat room.
This feature can be useful for highlighting important information.

## Syntax
`!spam [amount] [message...]`

+ `[amount]` (optional) - A number that specified how many times the message should be repeated.
+ `[message...]` - The text of the message to be repeated.

## Usage

+ `!spam forsen`
+ `!spam 100 forsen forsen forsen`

## Responses

```
forsen forsen forsen
forsen forsen forsen
forsen forsen forsen
forsen forsen forsen
forsen forsen forsen
forsen forsen forsen
forsen forsen forsen
forsen forsen forsen
forsen forsen forsen
forsen forsen forsen
...
]],
    delay_sec = 10,
    options = {},
    subcommands = {},
    aliases = {},
    minimal_rights = "moderator",
    handle = function(request)
        if request.message == nil then
            return l10n_custom_formatted_line_request(request, lines, "no_message", {})
        end

        local parts = str_split(request.message, " ")

        local max_count = 20
        local count = tonumber(parts[1])

        if count == nil then
            count = 5
        elseif count > max_count then
            count = max_count
            table.remove(parts, 1)
        else
            table.remove(parts, 1)
        end

        local msg = table.concat(parts, ' ')
        local o = {}

        for i = 1, count, 1 do
            table.insert(o, msg)
        end

        return o
    end
}