From ab27fb960aa8be6180e142813e75b31defd5a426 Mon Sep 17 00:00:00 2001 From: Stefan Hacker Date: Sat, 9 Apr 2011 03:51:10 +0200 Subject: [PATCH] Add new text message callback stub to mumo and modules. Add seen module to query for last time a given user was active. --- modules-available/seen.ini | 10 ++++ modules/bf2.py | 5 +- modules/idlemove.py | 9 ++-- modules/onjoin.py | 9 ++-- modules/seen.py | 93 ++++++++++++++++++++++++++++++++++++++ modules/test.py | 6 ++- mumo.py | 5 +- 7 files changed, 123 insertions(+), 14 deletions(-) create mode 100644 modules-available/seen.ini create mode 100644 modules/seen.py diff --git a/modules-available/seen.ini b/modules-available/seen.ini new file mode 100644 index 0000000..dceb3d9 --- /dev/null +++ b/modules-available/seen.ini @@ -0,0 +1,10 @@ +; +; This module allows asking the server for the last time it saw a specific +; player +; + +[seen] +; Comma seperated list of servers to operate on, leave empty for all +servers = +; Keyword to which the server reacts +keyword = !seen \ No newline at end of file diff --git a/modules/bf2.py b/modules/bf2.py index 1dda608..0017d69 100644 --- a/modules/bf2.py +++ b/modules/bf2.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -# Copyright (C) 2010 Stefan Hacker +# Copyright (C) 2010-2011 Stefan Hacker # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -359,7 +359,8 @@ class bf2(MumoModule): def userConnected(self, server, state, context = None): self.handle(server, state) - + + def userTextMessage(self, server, user, message, current=None): pass def channelCreated(self, server, state, context = None): pass def channelRemoved(self, server, state, context = None): pass def channelStateChanged(self, server, state, context = None): pass diff --git a/modules/idlemove.py b/modules/idlemove.py index ad94e0f..e94c232 100644 --- a/modules/idlemove.py +++ b/modules/idlemove.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -# Copyright (C) 2010 Stefan Hacker +# Copyright (C) 2010-2011 Stefan Hacker # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -37,11 +37,9 @@ # once they become active again # -from mumo_module import (x2bool, - commaSeperatedIntegers, +from mumo_module import (commaSeperatedIntegers, commaSeperatedBool, - MumoModule, - Config) + MumoModule) from threading import Timer import re @@ -204,6 +202,7 @@ class idlemove(MumoModule): self.UpdateUserAutoAway(server, state) def userConnected(self, server, state, context=None): pass # Unused callbacks + def userTextMessage(self, server, user, message, current=None): pass def channelCreated(self, server, state, context=None): pass def channelRemoved(self, server, state, context=None): pass def channelStateChanged(self, server, state, context=None): pass diff --git a/modules/onjoin.py b/modules/onjoin.py index 1f63348..66eb97a 100644 --- a/modules/onjoin.py +++ b/modules/onjoin.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -# Copyright (C) 2010 Stefan Hacker +# Copyright (C) 2010-2011 Stefan Hacker # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -35,10 +35,8 @@ # they connect regardless of which channel they were in when they left. # -from mumo_module import (x2bool, - commaSeperatedIntegers, - MumoModule, - Config) +from mumo_module import (commaSeperatedIntegers, + MumoModule) import re @@ -94,6 +92,7 @@ class onjoin(MumoModule): def userDisconnected(self, server, state, context = None): pass def userStateChanged(self, server, state, context = None): pass + def userTextMessage(self, server, user, message, current=None): pass def channelCreated(self, server, state, context = None): pass def channelRemoved(self, server, state, context = None): pass def channelStateChanged(self, server, state, context = None): pass diff --git a/modules/seen.py b/modules/seen.py new file mode 100644 index 0000000..de4bd4c --- /dev/null +++ b/modules/seen.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python +# -*- coding: utf-8 + +# Copyright (C) 2011 Stefan Hacker +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: + +# - Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# - Neither the name of the Mumble Developers nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# +# seen.py +# This module allows asking the server for the last time it saw a specific player +# + +from mumo_module import (commaSeperatedIntegers, + MumoModule) + +class seen(MumoModule): + default_config = {'seen':( + ('servers', commaSeperatedIntegers, []), + ('keyword', str, '!seen'), + ) + } + + def __init__(self, name, manager, configuration = None): + MumoModule.__init__(self, name, manager, configuration) + self.murmur = manager.getMurmurModule() + self.keyword = self.cfg().seen.keyword + + def connected(self): + manager = self.manager() + log = self.log() + log.debug("Register for Server callbacks") + + servers = self.cfg().seen.servers + if not servers: + servers = manager.SERVERS_ALL + + manager.subscribeServerCallbacks(self, servers) + + def disconnected(self): pass + + # + #--- Server callback functions + # + + def userTextMessage(self, server, user, message, current=None): + if message.text.startswith(self.keyword): + tuname = message.text[len(self.keyword):].strip() + self.log().debug("User %s (%d|%d) on server %d asking for '%s'", + user.name, user.session, user.userid, server.id(), tuname) + + for cuid, cuname in server.getRegisteredUsers(tuname).iteritems(): + if cuname == tuname: + ureg = server.getRegistration(cuid) + if ureg: + server.sendMessage(user.session, + "User '%s' was last active %s UTC" % (tuname, + ureg[self.murmur.UserInfo.UserLastActive])) + return + + server.sendMessage(user.session, + "I don't know who user '%s' is" % tuname) + + def userConnected(self, server, state, context = None): pass + def userDisconnected(self, server, state, context = None): pass + def userStateChanged(self, server, state, context = None): pass + + def channelCreated(self, server, state, context = None): pass + def channelRemoved(self, server, state, context = None): pass + def channelStateChanged(self, server, state, context = None): pass diff --git a/modules/test.py b/modules/test.py index 8ad9556..b909df3 100644 --- a/modules/test.py +++ b/modules/test.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -# Copyright (C) 2010 Stefan Hacker +# Copyright (C) 2010-2011 Stefan Hacker # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -91,6 +91,10 @@ class test(MumoModule): def userStateChanged(self, server, state, context = None): pass + @logModFu + def userTextMessage(self, server, user, message, current=None): + pass + @logModFu def channelCreated(self, server, state, context = None): pass diff --git a/mumo.py b/mumo.py index 9224193..3589d55 100644 --- a/mumo.py +++ b/mumo.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -# Copyright (C) 2010 Stefan Hacker +# Copyright (C) 2010-2011 Stefan Hacker # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -342,6 +342,9 @@ def do_main_program(): @checkSecret @forwardServer def channelStateChanged(self, c, current=None): pass + @checkSecret + @forwardServer + def userTextMessage(self, u, m, current=None) : pass class contextCallback(Murmur.ServerContextCallback): def __init__(self, manager, server, sid):