comparison plugins/xxstatus.py @ 0:4385a7d0efd1 grumpy-goblin

Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author sirebral
date Tue, 14 Jul 2009 16:41:58 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 import os
2 import orpg.pluginhandler
3 from random import randint
4 from time import time
5
6 class Plugin(orpg.pluginhandler.PluginHandler):
7 # Initialization subroutine.
8 #
9 # !self : instance of self
10 # !chat : instance of the chat window to write to
11 def __init__(self, plugindb, parent):
12 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent)
13
14 # The Following code should be edited to contain the proper information
15 self.name = 'Idle Time'
16 self.author = 'Woody, mDuo13'
17 self.help = "When you haven't sent a message to chat for a minute or more, this\n"
18 self.help += "plugin sets your status to end with '(* Mins)' where the * is however many\n"
19 self.help += "minutes you've been inactive. You can also set a custom message for the timed\n"
20 self.help += "idle by typing '/idle status *text*' where *text* is that message."
21
22 self.idle_timer_status = ''
23 self.start_time = ''
24 self.minutes = ''
25 self.last_update = ''
26
27 def plugin_enabled(self):
28 #This is where you set any variables that need to be initalized when your plugin starts
29 self.plugin_addcommand('/idle', self.on_idle, 'status - This sets your status to what ever you type')
30 self.reset_time()
31
32 def plugin_disabled(self):
33 #Here you need to remove any commands you added, and anything else you want to happen when you disable the plugin
34 #such as closing windows created by the plugin
35 self.plugin_removecmd('/idle')
36
37 def on_idle(self, cmdargs):
38 args = cmdargs.split(None,1)
39
40 if args[0] == 'status':
41 self.idle_timer_status = cmdargs[7:]
42 else:
43 self.chat.InfoPost("Invalid syntax for /idle command")
44
45 def reset_time(self):
46 self.start_time = time()
47 self.minutes = 0
48 self.last_update = 0
49
50 def pre_parse(self, text):
51 #This is called just before a message is parsed by openrpg
52 self.reset_time()
53 return text
54
55 def refresh_counter(self):
56 if self.idle_timer_status == '':
57 self.idle_timer_status = self.settings.get_setting("IdleStatusAlias")
58
59 current_time = time()
60 self.minutes = round((current_time - self.start_time)/60,1)
61
62 if self.minutes > 1:
63 plur = 's'
64 else:
65 plur = ''
66
67 if current_time - self.last_update >= 30:
68 self.session.set_text_status(self.idle_timer_status + ' (' + str(self.minutes) + ' min' + plur + ')')
69 self.last_update = time()