/usr/share/pyshared/jsb/lib/channelbase.py is in jsonbot 0.84.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | # jsb/channelbase.py
#
#
""" provide a base class for channels. """
## jsb imports
from jsb.utils.name import stripname
from jsb.utils.lazydict import LazyDict
from jsb.lib.persist import Persist
from jsb.lib.datadir import getdatadir
from jsb.utils.trace import whichmodule
from jsb.lib.errors import NoChannelProvided, NoChannelSet
## basic imports
import time
import os
import logging
## classes
class ChannelBase(Persist):
""" Base class for all channel objects. """
def __init__(self, id, botname=None, type="notset"):
if not id: raise NoChannelSet()
if not botname: Persist.__init__(self, getdatadir() + os.sep + 'channels' + os.sep + stripname(id))
else: Persist.__init__(self, getdatadir() + os.sep + 'fleet' + os.sep + stripname(botname) + os.sep + 'channels' + os.sep + stripname(id))
self.id = id
self.type = type
self.lastmodified = time.time()
self.data.id = id
self.data.enable = self.data.enable or False
self.data.ops = self.data.ops or []
self.data.silentcommands = self.data.silentcommands or []
self.data.allowcommands = self.data.allowcommands or []
self.data.feeds = self.data.feeds or []
self.data.forwards = self.data.forwards or []
self.data.allowwatch = self.data.allowwatch or []
self.data.watched = self.data.watched or []
self.data.passwords = self.data.passwords or {}
self.data.cc = self.data.cc or ""
self.data.nick = self.data.nick or "jsb"
self.data.key = self.data.key or ""
self.data.denyplug = self.data.denyplug or []
self.data.createdfrom = whichmodule()
self.data.cacheindex = 0
self.data.tokens = self.data.tokens or []
self.data.webchannels = self.data.webchannels or []
def setpass(self, type, key):
""" set channel password based on type. """
self.data.passwords[type] = key
self.save()
def getpass(self, type='IRC'):
""" get password based of type. """
try:
return self.data.passwords[type]
except KeyError: return
def delpass(self, type='IRC'):
""" delete password. """
try:
del self.data.passwords[type]
self.save()
return True
except KeyError: return
def parse(self, event, wavelet=None):
"""
parse an event for channel related data and constuct the
channel with it. Overload this.
"""
pass
def gae_create(self):
try:
from google.appengine.api import channel
id = self.id.split("_", 1)[0]
except ImportError: return (None, None)
#webchan = id + "_" + str(time.time())
webchan = id + "_" + str(time.time())
logging.warn("trying to create channel for %s" % webchan)
token = channel.create_channel(webchan)
#if token and token not in self.data.tokens:
# self.data.tokens.insert(0, token)
# self.data.tokens = self.data.tokens[:10]
if webchan not in self.data.webchannels:
self.data.webchannels.insert(0, webchan)
self.data.webchannels = self.data.webchannels[:2]
self.save()
return (webchan, token)
|