~ronnie.vd.c/+junk/MwanzoBot-Config

« back to all changes in this revision

Viewing changes to MwanzoBotV2.py

  • Committer: stefandevries1994 at gmail
  • Date: 2011-10-22 20:52:56 UTC
  • Revision ID: stefandevries1994@gmail.com-20111022205256-zfr7mtb7f55hieqz
FINAL BETA

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
        #!/usr/bin/env python
 
1
#!/usr/bin/env python
2
2
# -*- coding: utf-8 -*-
 
3
#       MwanzoBotV2.py
 
4
#       
 
5
#       Copyright 2011 Stefan de Vries <stefandevries1992@gmail.com>
 
6
#       
 
7
#       This program is free software; you can redistribute it and/or modify
 
8
#       it under the terms of the GNU General Public License as published by
 
9
#       the Free Software Foundation; either version 2 of the License, or
 
10
#       (at your option) any later version.
 
11
#       
 
12
#       This program is distributed in the hope that it will be useful,
 
13
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#       GNU General Public License for more details.
 
16
#       
 
17
#       You should have received a copy of the GNU General Public License
 
18
#       along with this program; if not, write to the Free Software
 
19
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
20
#       MA 02110-1301, USA.
3
21
 
4
22
import random, sys, socket, shelve, time
5
23
 
12
30
                self.canmeet = True
13
31
                self.candef = True
14
32
                self.conn = conn
15
 
                self.conn.send("JOIN :%s\r\n" % self.name)
16
 
                
 
33
                self.conn.send("JOIN :%s\r\n" % self.name)              
17
34
                
18
35
        def __del__(self):
19
36
                self.conn.send("PART %s :\r\n" % self.name)     
39
56
                                self.meetingnumber = random.randint(0, 10000000000)
40
57
                                filename = 'log' + str(self.meetingnumber) + '.html'
41
58
                                self.logfile = open('logs/' + filename, 'w')
42
 
                                self.logfile.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> <title>Log voor vergadering op ' + time.strftime('%x') + ' om ' + time.strftime('%X') + ' in ' + line[2] + '. Kengetal: ' + str(self.meetingnumber) +  '</title></head><body>')
 
59
                                self.logfile.write('<html><head><link rel="stylesheet" type="text/css" href="layout.css" /><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> <title>Log voor vergadering op ' + time.strftime('%x') + ' om ' + time.strftime('%X') + ' in ' + line[2] + '. Kengetal: ' + str(self.meetingnumber) +  '</title></head><body>')
43
60
                                self.chairs = []
44
61
                                chair = line[0].split('!')
45
62
                                self.chairs.append(chair[0])
101
118
                                        else:
102
119
                                                votestatus = 'Onbeslist'
103
120
                                        self.conn.send("PRIVMSG %s :Resultaten voor stemming aangaande: %s.\r\n" % (self.name, self.votetopic))
104
 
                                        self.logfile.write("Resultaten voor stemming aangaande: %s.<br />" % self.votetopic)
 
121
                                        self.logfile.write("Resultaten voor stemming aangaande: %s<br />" % self.votetopic)
105
122
                                        self.conn.send("PRIVMSG %s :+1: %s; -1: %s; 0: %s. %s.\r\n" % (self.name, self.votes[0], self.votes[1], self.votes[2], votestatus))
106
123
                                        self.logfile.write("+1: %s; -1: %s; 0: %s<br />" % (self.votes[0], self.votes[1], self.votes[2]))
107
124
                                        self.logfile.write("%s.<br />" % votestatus)
113
130
                                        
114
131
                                        
115
132
                        author = line[0].split('!')
 
133
                        author = author[0]
116
134
                        if line[2] != 'MwanzoBot_':
117
 
                                try:
118
 
                                        self.logfile.write('<b>'+ author[0] + '</b>' + ': ' + " ".join(line[3:]).lstrip(':') +'<br />\n')
 
135
                                try:                                    
 
136
                                        self.logfile.write('<b>'+ author + '</b>' + ': ' + " ".join(line[3:]).lstrip(':') +'<br />\n')
119
137
                                except ValueError:
120
138
                                        pass
121
139
                
126
144
                                if not line[0] in self.voted:
127
145
                                        self.votes[0] += 1
128
146
                                        self.conn.send("PRIVMSG %s :%s heeft gestemd.\r\n" % (self.name, line[0]))
129
 
                                        self.logfile.write(line[0] + ' heeft gestemd<br />')
 
147
                                        self.logfile.write(line[0] + ' heeft gestemd.<br />')
130
148
                                        self.voted.append(line[0])
131
149
                        elif line[3] == '-1' and int(line[4]) == self.votenumber and self.vote == True:
132
150
                                if not line[0] in self.voted:
133
151
                                        self.votes[1] += 1
134
152
                                        self.conn.send("PRIVMSG %s :%s heeft gestemd.\r\n" % (self.name, line[0]))
135
 
                                        self.logfile.write(line[0] + ' heeft gestemd<br />')
 
153
                                        self.logfile.write(line[0] + ' heeft gestemd.<br />')
136
154
                                        self.voted.append(line[0])
137
155
                        elif line[3] == '0' and int(line[4]) == self.votenumber and self.vote == True:
138
156
                                if not line[0] in self.voted:
139
157
                                        self.votes[2] += 0
140
158
                                        self.conn.send("PRIVMSG %s :%s heeft gestemd.\r\n" % (self.name, line[0]))
141
 
                                        self.logfile.write(line[0] + ' heeft gestemd<br />')
 
159
                                        self.logfile.write(line[0] + ' heeft gestemd.<br />')
142
160
                                        self.voted.append(line[0])
143
161
                
144
162
class MwanzoBotAdmin:
198
216
                                                                item.definitions = shelve.open(item.name)
199
217
                                                                item.definitions[line[4]] = " ".join(line[6:])                                          
200
218
                                                                item.definitions.close()
201
 
                                        elif line[3] == 'chanmode' and len(line) == 7:
 
219
                                        elif line[3] == 'cmod' and len(line) == 7:
 
220
                                                caller = line[0].split('!')
 
221
                                                caller = caller[0]
202
222
                                                for item in self.channels:
203
223
                                                        if line[4] == item.name:
204
224
                                                                if line[5] == 'meeting':
205
225
                                                                        if line[6] == 'true':
206
226
                                                                                item.canmeet = True
 
227
                                                                                conn.send("PRIVMSG %s :Meetingfunctionaliteit ingeschakeld voor %s\r\n" % (caller, line[4]))
207
228
                                                                        elif line[6] == 'false':
208
229
                                                                                item.canmeet = False
 
230
                                                                                conn.send("PRIVMSG %s :Meetingfunctionaliteit uitgeschakeld voor %s\r\n" % (caller, line[4]))
209
231
                                                                elif line[5] == 'def':
210
232
                                                                        if line[6] == 'true':
211
233
                                                                                item.candef = True
 
234
                                                                                conn.send("PRIVMSG %s :Definitiefunctionaliteit ingeschakeld voor %s\r\n" % (caller, line[4]))
212
235
                                                                        elif line[6] == 'false':
213
236
                                                                                item.candef = False
 
237
                                                                                conn.send("PRIVMSG %s :Definitiefunctionaliteit uitgeschakeld voor %s\r\n" % (caller, line[4]))
214
238
                                        elif line[3] == 'quit':
215
239
                                                conn.send("QUIT :Tot ziens!\r\n")
216
240
                                                sys.exit(0)
221
245
                                        for item in self.operators:
222
246
                                                conn.send("PRIVMSG %s :%s: %s\r\n" % (line[0][0], a, item))
223
247
                                                a += 1
224
 
                                if line[3] == 'ctrlop' and len(line) == 5:                              
 
248
                                elif line[3] == 'ctrlop' and len(line) == 5:                            
225
249
                                        if line[4].isdigit() and int(line[4]) == self.ctrlop[0]:
226
250
                                                self.operators.append(line[0])
227
251
                                                line[0] = line[0].split('!')
241
265
                                                item.currenttopic = " ".join(line[4:])
242
266
                                                print 'Topic saved!'
243
267
                                                                
244
 
                if line[1] == 'MODE':
 
268
                elif line[1] == 'MODE':
245
269
                        if line[3] == '+o':
246
270
                                for item in self.channels:
247
271
                                        if item.name == line[2]: