~ubuntu-branches/ubuntu/utopic/gozerbot/utopic

« back to all changes in this revision

Viewing changes to debian/gozerbot/usr/lib/python2.5/site-packages/gozerbot/botbase.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2009-09-14 09:00:29 UTC
  • mfrom: (1.1.4 upstream) (3.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090914090029-uval0ekt72kmklxw
Tags: 0.9.1.3-3
Changed dependency on python-setuptools to python-pkg-resources
(Closes: #546435) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# gozerbot/botbase.py
2
 
#
3
 
#
4
 
 
5
 
""" bot base class """
6
 
 
7
 
from gozerbot.generic import rlog
8
 
from gozerbot.less import Less
9
 
from gozerbot.pdol import Pdol
10
 
from gozerbot.dol import Dol
11
 
from gozerbot.persiststate import PersistState
12
 
from gozerbot.runner import runner
13
 
from gozerbot.eventhandler import commandhandler
14
 
from gozerbot.channels import Channels
15
 
from gozerbot.datadir import datadir
16
 
from gozerbot.pdod import Pdod
17
 
from gozerbot.config import config
18
 
import time, threading, os, types
19
 
 
20
 
class BotBase(object):
21
 
 
22
 
    def __init__(self, name='main', owner=[]):
23
 
        self.name = name
24
 
        self.owner = owner
25
 
        self.type = "irc"
26
 
        self.nick = ""
27
 
        self.orignick = ""
28
 
        self.server = ""
29
 
        self.port = None
30
 
        self.ssl = False
31
 
        self.password = ""
32
 
        self.ipv6 = False
33
 
        self.blocking = True
34
 
        self.lastoutput = 0
35
 
        self.stopped = False
36
 
        self.connected = False
37
 
        self.connecting = False
38
 
        self.connectok = threading.Event()
39
 
        self.starttime = time.time()
40
 
        self.nrevents = 0
41
 
        self.gcevents = 0
42
 
        self.less = Less(5)
43
 
        self.userchannels = Dol()
44
 
        self.channels = Channels(datadir + os.sep + '%s.channels' % self.name)
45
 
        self.userhosts = PersistState(datadir + os.sep + '%s.userhosts' % \
46
 
self.name)
47
 
        self.state = Pdod(datadir + os.sep + '%s.state' % self.name)
48
 
        if not self.state.has_key('joinedchannels'):
49
 
            self.state['joinedchannels'] = []
50
 
        if not self.state.has_key('allowed'):
51
 
            self.state['allowed'] = []
52
 
        self.jabber = False
53
 
        self.google = False
54
 
        runner.start()
55
 
        commandhandler.start()
56
 
 
57
 
    def ownercheck(self, ievent, txt=None):
58
 
        if self.jabber:
59
 
            owner = self.owner or config['jabberowner']
60
 
        else:
61
 
            owner = self.owner or config['owneruserhost']
62
 
        if type(owner) == types.ListType:           
63
 
            if ievent.userhost in owner:            
64
 
                return 1
65
 
        elif owner == ievent.userhost:              
66
 
            return 1    
67
 
        else:
68
 
            if not txt:
69
 
                ievent.reply("only owner (see config file) is allowed \
70
 
to perform this command")
71
 
            else:
72
 
                ievent.reply("only owner (see config file) %s" % txt)
73
 
            return 0
74
 
 
75
 
    def save(self):
76
 
        self.channels.save()
77
 
        self.userhosts.save()
78
 
        self.state.save()
79
 
 
80
 
    def stop(self):
81
 
        self.stopped = True
82
 
        rlog(10, self.name, 'stopped')
83
 
 
84
 
    def exit(self):
85
 
        pass
86
 
 
87
 
    def connect(self):
88
 
        pass
89
 
 
90
 
    def joinchannels(self):
91
 
        pass
92
 
 
93
 
    def broadcast(self):
94
 
        pass
95
 
 
96
 
    def send(self, txt):
97
 
        pass
98
 
 
99
 
    def shutdown(self):
100
 
        pass