mirror of
https://github.com/evennia/evennia.git
synced 2026-03-26 09:46:32 +01:00
Starting to convert RSS to new system
This commit is contained in:
parent
fc89923fa8
commit
c0417def6d
3 changed files with 99 additions and 8 deletions
|
|
@ -15,7 +15,6 @@ _IDLE_TIMEOUT = settings.IDLE_TIMEOUT
|
|||
_IDLE_COMMAND = settings.IDLE_COMMAND
|
||||
|
||||
_SESSIONS = None
|
||||
_CHANNELDB = None
|
||||
|
||||
|
||||
# Bot helper utilities
|
||||
|
|
@ -44,7 +43,7 @@ class BotStarter(Script):
|
|||
|
||||
def at_repeat(self):
|
||||
"Called self.interval seconds to keep connection."
|
||||
self.dbobj.execute_cmd(_IDLE_COMMAND)
|
||||
self.obj.dbobj.execute_cmd(_IDLE_COMMAND)
|
||||
|
||||
def at_server_reload(self):
|
||||
"""
|
||||
|
|
@ -97,7 +96,7 @@ class Bot(Player):
|
|||
self.locks.add(lockstring)
|
||||
# set the basics of being a bot
|
||||
self.cmdset.add_default(BotCmdSet)
|
||||
script_key = "botstarter_%s" % self.key
|
||||
script_key = "%s" % self.key
|
||||
self.scripts.add(BotStarter, key=script_key)
|
||||
self.is_bot = True
|
||||
|
||||
|
|
@ -136,7 +135,7 @@ class IRCBot(Bot):
|
|||
irc_network - url of network, like irc.freenode.net
|
||||
irc_port - port number of irc network, like 6667
|
||||
"""
|
||||
global _SESSIONS, _CHANNELDB
|
||||
global _SESSIONS
|
||||
if not _SESSIONS:
|
||||
from src.server.sessionhandler import SESSIONS as _SESSIONS
|
||||
|
||||
|
|
@ -193,3 +192,51 @@ class IRCBot(Bot):
|
|||
self.ndb.ev_channel = self.db.ev_channel
|
||||
if self.ndb.ev_channel:
|
||||
self.ndb.ev_channel.msg(text, senders=self.dbobj.id)
|
||||
|
||||
|
||||
class RSSBot(Bot):
|
||||
"""
|
||||
An RSS relayer. The RSS protocol itself runs a ticker to update its feed at regular
|
||||
intervals.
|
||||
"""
|
||||
def start(self, ev_channel=None, rss_url=None, rss_update_rate=None):
|
||||
"""
|
||||
Start by telling the portal to start a new RSS session
|
||||
|
||||
ev_channel - key of the Evennia channel to connect to
|
||||
rss_url - full URL to the RSS feed to subscribe to
|
||||
rss_update_rate - how often for the feedreader to update
|
||||
"""
|
||||
global _SESSIONS
|
||||
if not _SESSIONS:
|
||||
from src.server.sessionhandler import SESSIONS as _SESSIONS
|
||||
|
||||
if ev_channel:
|
||||
# connect to Evennia channel
|
||||
channel = search.channel_search(ev_channel)
|
||||
if not channel:
|
||||
raise RuntimeError("Evennia Channel '%s' not found." % ev_channel)
|
||||
channel = channel[0]
|
||||
self.db.ev_channel = channel
|
||||
if rss_url:
|
||||
self.db.rss_url = rss_url
|
||||
if rss_update_rate:
|
||||
self.db.rss_update_rate = rss_update_rate
|
||||
# instruct the server and portal to create a new session with
|
||||
# the stored configuration
|
||||
configdict = {"uid": self.dbid,
|
||||
"url": self.db.rss_url,
|
||||
"rate": self.db.rss_update_rate}
|
||||
_SESSIONS.start_bot_session("src.server.portal.rss.RSSBotFactory", configdict)
|
||||
|
||||
def execute_cmd(self, text=None, sessid=None):
|
||||
"""
|
||||
Echo RSS input to connected channel
|
||||
"""
|
||||
if not self.ndb.ev_channel and self.db.ev_channel:
|
||||
# cache channel lookup
|
||||
self.ndb.ev_channel = self.db.ev_channel
|
||||
if self.ndb.ev_channel:
|
||||
self.ndb.ev_channel.msg(text, senders=self.dbobj.id)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -26,12 +26,13 @@ Common examples of uses of Scripts:
|
|||
"""
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
|
||||
from src.typeclasses.models import (TypedObject, TagHandler,
|
||||
AttributeHandler)
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from src.typeclasses.models import TypedObject, TagHandler, AttributeHandler
|
||||
from src.scripts.manager import ScriptManager
|
||||
from src.utils.utils import dbref, to_str
|
||||
|
||||
__all__ = ("ScriptDB",)
|
||||
_GA = object.__getattribute__
|
||||
_SA = object.__setattr__
|
||||
|
||||
|
||||
|
|
@ -113,12 +114,54 @@ class ScriptDB(TypedObject):
|
|||
_SA(self, "tags", TagHandler(self))
|
||||
#_SA(self, "aliases", AliasHandler(self))
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
# ScriptDB class properties
|
||||
#
|
||||
#
|
||||
|
||||
# obj property
|
||||
def __get_obj(self):
|
||||
"""
|
||||
property wrapper that homogenizes access to either
|
||||
the db_player or db_obj field, using the same obj
|
||||
property name
|
||||
"""
|
||||
if self.db_player:
|
||||
return _GA(self, "db_player")
|
||||
return _GA(self, "db_obj")
|
||||
|
||||
def __set_obj(self, value):
|
||||
"""
|
||||
Set player or obj to their right database field. If
|
||||
a dbref is given, assume ObjectDB.
|
||||
"""
|
||||
try:
|
||||
value = _GA(value, "dbobj")
|
||||
except AttributeError:
|
||||
pass
|
||||
if isinstance(value, (basestring, int)):
|
||||
from src.objects.models import ObjectDB
|
||||
value = to_str(value, force_string=True)
|
||||
if (value.isdigit() or value.startswith("#")):
|
||||
dbid = dbref(value, reqhash=False)
|
||||
if dbid:
|
||||
try:
|
||||
value = ObjectDB.objects.get(id=dbid)
|
||||
except ObjectDoesNotExist:
|
||||
# maybe it is just a name that happens to look like a dbid
|
||||
pass
|
||||
if value.__class__.__name__ == "PlayerDB":
|
||||
fname = "db_player"
|
||||
_SA(self, fname, value)
|
||||
else:
|
||||
fname = "db_obj"
|
||||
_SA(self, fname, value)
|
||||
# saving the field
|
||||
_GA(self, "save")(update_fields=[fname])
|
||||
obj = property(__get_obj, __set_obj)
|
||||
|
||||
|
||||
def at_typeclass_error(self):
|
||||
"""
|
||||
|
|
@ -134,6 +177,7 @@ class ScriptDB(TypedObject):
|
|||
|
||||
delete_iter = 0
|
||||
def delete(self):
|
||||
"Delete script"
|
||||
if self.delete_iter > 0:
|
||||
return
|
||||
self.delete_iter += 1
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class GameTime(Script):
|
|||
Setup the script
|
||||
"""
|
||||
self.key = GAMETIME_SCRIPT_NAME
|
||||
self.desc = "Keeps track of the game time"
|
||||
self.desc = "Saves uptime/runtime"
|
||||
self.interval = 60
|
||||
self.persistent = True
|
||||
self.start_delay = True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue