mirror of
https://github.com/Oreolek/mod_muc_rpg.git
synced 2024-05-05 02:18:14 +03:00
Trying to get it working
This commit is contained in:
parent
c973475017
commit
f353b753cd
|
@ -11,6 +11,7 @@ The syntax is this:
|
||||||
The `<times>` bit is optional (default 1), the `d` letter is optional too if `times` = 1 and `bonus` = 0.
|
The `<times>` bit is optional (default 1), the `d` letter is optional too if `times` = 1 and `bonus` = 0.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
/roll 1d4
|
/roll 1d4
|
||||||
/roll 2d5-2
|
/roll 2d5-2
|
||||||
/roll d20+3
|
/roll d20+3
|
||||||
|
@ -22,6 +23,6 @@ This module uses Mersenne-Twister random-number library for better random number
|
||||||
|
|
||||||
You can get the newest library version [here.](http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html)
|
You can get the newest library version [here.](http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html)
|
||||||
|
|
||||||
The library uses BSD license so it's included here (for Lua 5.2). Just compile the `random.so` and put it in plugin directory.
|
The library uses BSD license so it's included here (for Lua 5.2). Just compile the `random.so` and put it in `/usr/lib/prosody` or `/usr/lib/lua/5.1` directory.
|
||||||
|
|
||||||
Then, drop the module to Prosody dir (usually `/usr/lib/prosody/modules`) and turn it on in your config.
|
Then, drop the module to Prosody dir (usually `/usr/lib/prosody/modules`) and turn it on in your config.
|
||||||
|
|
|
@ -3,10 +3,9 @@
|
||||||
-- based on mod_muc_intercom by Kim Alvefur <zash@zash.se>
|
-- based on mod_muc_intercom by Kim Alvefur <zash@zash.se>
|
||||||
|
|
||||||
local host_session = prosody.hosts[module.host];
|
local host_session = prosody.hosts[module.host];
|
||||||
local st_msg = require "util.stanza".message;
|
|
||||||
local jid = require "util.jid";
|
local jid = require "util.jid";
|
||||||
local random=require"random"
|
--local random = require"random"
|
||||||
r=random.new(os.time())
|
--r=random.new(os.time())
|
||||||
|
|
||||||
local function get_room_by_jid(mod_muc, jid)
|
local function get_room_by_jid(mod_muc, jid)
|
||||||
if mod_muc.get_room_by_jid then
|
if mod_muc.get_room_by_jid then
|
||||||
|
@ -16,13 +15,13 @@ local function get_room_by_jid(mod_muc, jid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function roll (times, sides, bonus)
|
local function roll (times, sides, bonus)
|
||||||
local result = {}
|
local result = {}
|
||||||
result.dice = {}
|
result.dice = {}
|
||||||
bonus = bonus or 0
|
bonus = bonus or 0
|
||||||
|
|
||||||
for i = 1, times do
|
for i = 1, times do
|
||||||
result.dice[#result.dice + 1] = r(sides)
|
result.dice[#result.dice + 1] = math.random(sides)
|
||||||
end
|
end
|
||||||
|
|
||||||
result.bonus = bonus
|
result.bonus = bonus
|
||||||
|
@ -30,7 +29,7 @@ function roll (times, sides, bonus)
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
function parseroll(message)
|
local function parseroll(message)
|
||||||
local result = {}
|
local result = {}
|
||||||
result.times = 1
|
result.times = 1
|
||||||
result.sides = 20
|
result.sides = 20
|
||||||
|
@ -60,29 +59,35 @@ function parseroll(message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function check_message(data)
|
local function check_message(data)
|
||||||
local origin, stanza = data.origin, data.stanza;
|
local stanza = data.stanza;
|
||||||
local mod_muc = host_session.muc;
|
local body = stanza:get_child("body");
|
||||||
|
|
||||||
|
if not body then return; end -- No body, like topic changes
|
||||||
|
if not (stanza.name == "message" and tostring(stanza.attr.type) == "groupchat") then return; end
|
||||||
if not mod_muc then return; end
|
if not mod_muc then return; end
|
||||||
|
|
||||||
local this_room = get_room_by_jid(mod_muc, stanza.attr.to);
|
local mod_muc = host_session.muc;
|
||||||
if not this_room then return; end -- no such room
|
data.stanza.body = "hello"
|
||||||
|
|
||||||
local from_room_jid = this_room._jid_nick[stanza.attr.from];
|
|
||||||
if not from_room_jid then return; end -- no such nick
|
|
||||||
|
|
||||||
local from_room, from_host, from_nick = jid.split(from_room_jid);
|
|
||||||
|
|
||||||
local body = stanza:get_child("body");
|
|
||||||
if not body then return; end -- No body, like topic changes
|
|
||||||
body = body and body:get_text();
|
body = body and body:get_text();
|
||||||
if not string.match(body, '^%s*/roll%s') then return; end -- No command
|
if not string.match(body, '^%s*/roll%s') then return; end -- No command
|
||||||
local message = body:match("^@([^:]+):(.*)");
|
local message = body:match("^@([^:]+):(.*)");
|
||||||
if not message then return; end
|
if not message then return; end
|
||||||
|
|
||||||
local forward_stanza = st_msg({from = sender, to = this_room, type = "groupchat"}, message);
|
stanza.body = body .. " rolled: "
|
||||||
|
local result = roll(parseroll(message))
|
||||||
|
|
||||||
this_room:broadcast_message(forward_stanza);
|
local total = 0
|
||||||
|
for i = 1, #result.dice do
|
||||||
|
if i == 1 then
|
||||||
|
stanza.body = stanza.body .. result.dice[i]
|
||||||
|
else
|
||||||
|
stanza.body = stanza.body .. "," .. result.dice[i]
|
||||||
|
end
|
||||||
|
total = total + result.dice[i]
|
||||||
|
end
|
||||||
|
total = total + result.bonus
|
||||||
|
data.stanza.body = stanza.body .. ", total: " .. total
|
||||||
end
|
end
|
||||||
|
|
||||||
module:hook("message/bare", check_message, 10);
|
module:hook("message/bare", check_message, 10);
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
# these will probably work if Lua has been installed globally
|
# these will probably work if Lua has been installed globally
|
||||||
LUA= /usr
|
LUA= /usr
|
||||||
LUAINC= $(LUA)/include
|
LUAINC= $(LUA)/include/lua5.1
|
||||||
LUALIB= $(LUA)/lib
|
LUALIB= $(LUA)/lib/lua5.1
|
||||||
LUABIN= $(LUA)/bin
|
LUABIN= $(LUA)/bin
|
||||||
|
|
||||||
# probably no need to change anything below here
|
# probably no need to change anything below here
|
||||||
|
|
Loading…
Reference in a new issue