plugins/version.lua

Thu, 23 Mar 2023 09:54:45 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 23 Mar 2023 09:54:45 +0000
changeset 174
56316e345595
parent 126
99781a97f582
permissions
-rw-r--r--

squishy: Add missing servercontact plugin

0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local st = require "util.stanza";
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local xmlns_version = "jabber:iq:version";
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
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
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 function riddim.plugins.version(bot)
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 bot.stream:add_plugin("version");
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 bot.stream.version:set{
76
cecdfba8e625 plugins/version improvements
mva <mva@mva.name>
parents: 37
diff changeset
14 name = bot.config.bot_name or "Riddim";
cecdfba8e625 plugins/version improvements
mva <mva@mva.name>
parents: 37
diff changeset
15 version = bot.config.bot_version or "alpha";
cecdfba8e625 plugins/version improvements
mva <mva@mva.name>
parents: 37
diff changeset
16 platform = bot.config.bot_platform or _VERSION;
0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 };
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
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
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
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
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
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
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 end
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
26 bot.stream:query_version(who, function (reply)
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
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
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
37 else
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
38 local type, condition, text = reply.type, reply.condition, reply.text;
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
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
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
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
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 end
16
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
46 if text then
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
47 r = r .. " ("..text..")";
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
48 end
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
49 command:reply(r);
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
50 end
ae69cea97598 Formatting, indentation and cleanup
Chris <jugg@hotmail.com>
parents: 7
diff changeset
51 end);
0
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 return true;
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 end);
7d84f4403d67 Initial commit, hello world!
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 end

mercurial