Wed, 15 Mar 2023 12:10:00 +0000
Dockerfile: update to bullseye
0 | 1 | local st = require "util.stanza"; |
2 | ||
3 | local xmlns_version = "jabber:iq:version"; | |
4 | ||
125
2c570064f582
plugins.version: Put friendly errors in a table
Kim Alvefur <zash@zash.se>
parents:
113
diff
changeset
|
5 | local friendly_errors = { |
2c570064f582
plugins.version: Put friendly errors in a table
Kim Alvefur <zash@zash.se>
parents:
113
diff
changeset
|
6 | ["service-unavailable"] = " doesn't reply to version requests"; |
2c570064f582
plugins.version: Put friendly errors in a table
Kim Alvefur <zash@zash.se>
parents:
113
diff
changeset
|
7 | ["feature-not-implemented"] = " doesn't support version requests"; |
2c570064f582
plugins.version: Put friendly errors in a table
Kim Alvefur <zash@zash.se>
parents:
113
diff
changeset
|
8 | ["remote-server-not-found"] = " can't be reached via XMPP"; |
2c570064f582
plugins.version: Put friendly errors in a table
Kim Alvefur <zash@zash.se>
parents:
113
diff
changeset
|
9 | } |
2c570064f582
plugins.version: Put friendly errors in a table
Kim Alvefur <zash@zash.se>
parents:
113
diff
changeset
|
10 | |
0 | 11 | function riddim.plugins.version(bot) |
12 | bot.stream:add_plugin("version"); | |
13 | bot.stream.version:set{ | |
76 | 14 | name = bot.config.bot_name or "Riddim"; |
15 | version = bot.config.bot_version or "alpha"; | |
16 | platform = bot.config.bot_platform or _VERSION; | |
0 | 17 | }; |
18 | ||
105
4234c8789cc6
plugins.{ping,version,resolvejid}: Break nickname/jid resolving into a common plugin
Kim Alvefur <zash@zash.se>
parents:
76
diff
changeset
|
19 | bot:add_plugin("resolvejid"); |
0 | 20 | bot:hook("commands/version", function (command) |
37
85b3f2a96edb
plugins.version: Report own version in first person, and don't crash if it's not in a room
Kim Alvefur <zash@zash.se>
parents:
33
diff
changeset
|
21 | local who, param = bot.stream.jid, command.param; |
0 | 22 | if param then |
105
4234c8789cc6
plugins.{ping,version,resolvejid}: Break nickname/jid resolving into a common plugin
Kim Alvefur <zash@zash.se>
parents:
76
diff
changeset
|
23 | who = bot:resolvejid(param, command.room); |
0 | 24 | end |
25 | ||
16 | 26 | bot.stream:query_version(who, function (reply) |
27 | if not reply.error then | |
37
85b3f2a96edb
plugins.version: Report own version in first person, and don't crash if it's not in a room
Kim Alvefur <zash@zash.se>
parents:
33
diff
changeset
|
28 | local saywho = (who == command.sender.jid and "You are") or (param and param.." is" or "I am"); |
126
99781a97f582
plugins.version: Don't include unknown version or platform in reply
Kim Alvefur <zash@zash.se>
parents:
125
diff
changeset
|
29 | local isrunning = saywho.." running "..(reply.name or "something"); |
99781a97f582
plugins.version: Don't include unknown version or platform in reply
Kim Alvefur <zash@zash.se>
parents:
125
diff
changeset
|
30 | if reply.version then |
99781a97f582
plugins.version: Don't include unknown version or platform in reply
Kim Alvefur <zash@zash.se>
parents:
125
diff
changeset
|
31 | isrunning = isrunning .." version "..reply.version; |
99781a97f582
plugins.version: Don't include unknown version or platform in reply
Kim Alvefur <zash@zash.se>
parents:
125
diff
changeset
|
32 | end |
99781a97f582
plugins.version: Don't include unknown version or platform in reply
Kim Alvefur <zash@zash.se>
parents:
125
diff
changeset
|
33 | if reply.platform then |
99781a97f582
plugins.version: Don't include unknown version or platform in reply
Kim Alvefur <zash@zash.se>
parents:
125
diff
changeset
|
34 | isrunning = isrunning .." on "..reply.platform; |
99781a97f582
plugins.version: Don't include unknown version or platform in reply
Kim Alvefur <zash@zash.se>
parents:
125
diff
changeset
|
35 | end |
99781a97f582
plugins.version: Don't include unknown version or platform in reply
Kim Alvefur <zash@zash.se>
parents:
125
diff
changeset
|
36 | command:reply(isrunning); |
16 | 37 | else |
38 | local type, condition, text = reply.type, reply.condition, reply.text; | |
39 | local r = "There was an error requesting "..param.."'s version"; | |
125
2c570064f582
plugins.version: Put friendly errors in a table
Kim Alvefur <zash@zash.se>
parents:
113
diff
changeset
|
40 | local friendly_error = friendly_errors[condition]; |
2c570064f582
plugins.version: Put friendly errors in a table
Kim Alvefur <zash@zash.se>
parents:
113
diff
changeset
|
41 | if friendly_error then |
2c570064f582
plugins.version: Put friendly errors in a table
Kim Alvefur <zash@zash.se>
parents:
113
diff
changeset
|
42 | r = r .. friendly_error; |
16 | 43 | elseif condition and not text then |
125
2c570064f582
plugins.version: Put friendly errors in a table
Kim Alvefur <zash@zash.se>
parents:
113
diff
changeset
|
44 | r = r..": "..(condition):gsub("%-", " "); |
0 | 45 | end |
16 | 46 | if text then |
47 | r = r .. " ("..text..")"; | |
48 | end | |
49 | command:reply(r); | |
50 | end | |
51 | end); | |
0 | 52 | return true; |
53 | end); | |
54 | end |