plugins/presence.lua

Thu, 03 Sep 2015 22:41:27 +0200

author
Kim Alvefur <zash@zash.se>
date
Thu, 03 Sep 2015 22:41:27 +0200
changeset 395
e86144a4eaa1
parent 250
a5ac643a7fd6
child 404
7c6a610c3ff5
permissions
-rw-r--r--

plugins: Cleanup [luacheck]

250
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 197
diff changeset
1 local verse = require "verse";
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 197
diff changeset
2
177
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 function verse.plugins.presence(stream)
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 stream.last_presence = nil;
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 stream:hook("presence-out", function (presence)
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 if not presence.attr.to then
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 stream.last_presence = presence; -- Cache non-directed presence
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 end
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 end, 1);
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 function stream:resend_presence()
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 if last_presence then
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 stream:send(last_presence);
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 end
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 end
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 function stream:set_status(opts)
197
7e98cf2c1d8d plugins.*: Use verse.stanza() & co instead of require util.stanza
Kim Alvefur <zash@zash.se>
parents: 191
diff changeset
19 local p = verse.presence();
177
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 if type(opts) == "table" then
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 if opts.show then
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 p:tag("show"):text(opts.show):up();
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 end
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 if opts.prio then
191
e0664081654c plugins.presence: Fix priority setting. (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents: 177
diff changeset
25 p:tag("priority"):text(tostring(opts.prio)):up();
177
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 end
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 if opts.msg then
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 p:tag("status"):text(opts.msg):up();
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 end
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 end
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 -- TODO maybe use opts as prio if it's a int,
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 -- or as show or status if it's a string?
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 stream:send(p);
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 end
0ffb565fcfd6 plugins.presence: Initial commit of plugin that caches the last outgoing presence, and handles rebroadcast
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 end

mercurial