summaryrefslogtreecommitdiff
path: root/luamods/settings.lua
blob: 1ac037ab4727e3c98f53c12011593b359fa8ff6f (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
local lines = {
    english = {
        ["no_value"] = "{sender.alias_name}: Value must be provided.",
        ["no_subcommand"] =
        "{sender.alias_name}: Subcommand must be provided. Use {channel.prefix}help to get more information.",
        ["locale_not_exists"] = "{sender.alias_name}: Language %s not found",
        ["set_locale"] = "{sender.alias_name}: This bot will speak English in this chat!",
        ["set_prefix"] = "{sender.alias_name}: Prefix \"%s\" has been set for this chat!",
        ["no_feature"] = "{sender.alias_name}: Feature %s not found",
        ["feature_disabled"] = "{sender.alias_name}: Feature %s has been disabled",
        ["feature_enabled"] = "{sender.alias_name}: Feature %s has been enabled"
    },
    russian = {
        ["no_value"] = "{sender.alias_name}: Значение требуется для этой команды.",
        ["no_subcommand"] =
        "{sender.alias_name}: Подкоманда требуется для этой команды. Используйте {channel.prefix}help для большей информации.",
        ["locale_not_exists"] = "{sender.alias_name}: Язык %s не найден",
        ["set_locale"] = "{sender.alias_name}: Этот бот будет говорить по-русски!",
        ["set_prefix"] = "{sender.alias_name}: Префикс \"%s\" установлен для этого чата!",
        ["no_feature"] = "{sender.alias_name}: Функция %s не найдена",
        ["feature_disabled"] = "{sender.alias_name}: Функция %s теперь выключена",
        ["feature_enabled"] = "{sender.alias_name}: Функция %s теперь включена"
    },
}

return {
    name = "set",
    description = [[
> This command is for broadcaster and moderators only.


The `!set` command gives broadcasters ability to customize the bot as they need it to be more fitted for chat.


## Available features

+ `markov_responses` - Enable Markov-generated responses *(triggered by "@teabot, " prefix)*
+ `random_markov_responses` - Enable Markov-generated responses on random messages. It is required that the feature `markov_responses` is enabled.

## Syntax

### Set the bot localization for the chat
`!set locale [lang]`

+ `[lang]` - Language name in English and lowercase.
Available languages at the moment: **english**, **russian**.

### Set the bot prefix
`!set prefix [characters]`

+ `[characters]` - Characters to be set as a prefix.

### Enable/disable the bot feature for the chat
`!set feature [feature]`

+ `[feature]` - [Available features](#available-features)

## Usage

### Setting the bot localization

+ `!set locale russian`
+ `!set locale english`

### Setting the bot prefix

+ `!set prefix ~`
+ `!set prefix ?!`

### Enabling/disabling the bot feature

+ `!set feature notify_7tv_updates`

## Responses

### Setting the bot localization

+ `Успешно установил язык чата на русский!`
+ `Successfully set the chat language to English!`

### Setting the bot prefix

+ `Successfully set the chat prefix to "~"`
+ `Successfully set the chat prefix to "?!"`

### Enabling/disabling the bot feature

+ `Successfully enabled the "markov_responses" feature for this chat!`
+ `Successfully disabled the "random_markov_responses" feature for this chat!`
]],
    delay_sec = 1,
    options = {},
    subcommands = { "locale", "prefix", "feature" },
    aliases = {},
    minimal_rights = "moderator",
    handle = function(request)
        if request.subcommand_id == nil then
            return l10n_custom_formatted_line_request(request, lines, "no_subcommand", {})
        end

        if request.message == nil then
            return l10n_custom_formatted_line_request(request, lines, "no_value", {})
        end

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

        local value = parts[1]

        if request.subcommand_id == "locale" then
            local locals = l10n_get_localization_names()
            if not array_contains(locals, value) then
                return l10n_custom_formatted_line_request(request, lines, "locale_not_exists", { value })
            end

            db_execute('UPDATE channel_preferences SET locale = $1 WHERE channel_id = $2', { value, request.channel.id })
            request['channel_preference']['language'] = value

            return l10n_custom_formatted_line_request(request, lines, "set_locale", {})
        elseif request.subcommand_id == "prefix" then
            value = value:gsub(" ", " ")
            db_execute('UPDATE channel_preferences SET prefix = $1 WHERE channel_id = $2', { value, request.channel.id })
            return l10n_custom_formatted_line_request(request, lines, "set_prefix", { value })
        elseif request.subcommand_id == "feature" then
            local feature = str_to_feature(value)
            if feature == nil then
                return l10n_custom_formatted_line_request(request, lines, "no_feature", { value })
            end

            local channel_features = request.channel_preference.features

            local line_id = ""
            local query = ""

            if array_contains(channel_features, value) then
                line_id = "feature_disabled"
                query = 'UPDATE channel_preferences SET features = array_remove(features, $1) WHERE channel_id = $2'
            else
                line_id = "feature_enabled"
                query = 'UPDATE channel_preferences SET features = array_append(features, $1) WHERE channel_id = $2'
            end

            db_execute(query, { feature, request.channel.id })

            return l10n_custom_formatted_line_request(request, lines, line_id, { value })
        end
    end,
}