summaryrefslogtreecommitdiff
path: root/plugins/autospell.py
diff options
context:
space:
mode:
authorLivio Recchia <recchialivio@libero.it>2020-02-10 23:06:34 +0100
committerLivio Recchia <recchialivio@libero.it>2020-02-10 23:06:34 +0100
commit9a13903a2f7d3a65fdf15a65fb59cccd622e2066 (patch)
tree9403b7dff39eb5e5d7fa0f79efb69b496add4c4b /plugins/autospell.py
parent11cc316b74d5f3f283413a33e7693b314741aa4a (diff)
downloadmanachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.tar.gz
manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.tar.bz2
manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.tar.xz
manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.zip
Initial commit
Diffstat (limited to 'plugins/autospell.py')
-rw-r--r--plugins/autospell.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/plugins/autospell.py b/plugins/autospell.py
new file mode 100644
index 0000000..30d0ec6
--- /dev/null
+++ b/plugins/autospell.py
@@ -0,0 +1,57 @@
+import re
+import time
+import commands
+import net.mapserv as mapserv
+from loggers import debuglog
+from logicmanager import logic_manager
+
+__all__ = [ 'PLUGIN', 'init' ]
+
+PLUGIN = {
+ 'name': 'autospell',
+ 'requires': (),
+ 'blocks': (),
+ 'default_config' : {}
+}
+
+as_re = re.compile(r'(\d+) (\d+) (.+)')
+times = 0
+delay = 0
+spell = ''
+next_ts = 0
+
+
+def cmd_autospell(_, arg):
+ '''Cast a spell multiple times automatically
+/autospell TIMES DELAY SPELL'''
+ global times, delay, spell, next_ts
+ m = as_re.match(arg)
+ if m:
+ times = int(m.group(1))
+ delay = int(m.group(2))
+ spell = m.group(3)
+ else:
+ debuglog.warning("Usage: /autospell TIMES DELAY SPELL")
+ return
+
+ next_ts = time.time() + delay
+
+
+def cmd_stopspell(*unused):
+ '''Stop casting autospells'''
+ global times, delay, spell, next_ts
+ times = delay = next_ts = 0
+
+
+def autospell_logic(ts):
+ global times, next_ts
+ if times > 0 and ts >= next_ts:
+ times -= 1
+ next_ts = ts + delay
+ mapserv.cmsg_chat_message(spell)
+
+
+def init(config):
+ commands.commands['autospell'] = cmd_autospell
+ commands.commands['stopspell'] = cmd_stopspell
+ logic_manager.add_logic(autospell_logic)