Hi guys Thanks for helping me so here in cause of you , is my new plugin
here is always my latest version current is 0.0.6
(
http://rapidshare.com/files/181498156/The_brain.zip.html ->
File is no longer available)
What it does better then the older censord words plugin
1. you can easy add bad words with ingame command !bwadd
2. Its harder to trick so if you added [****] it will discover f u c k or f.u..c k and mutch more just try it even looooooooooooooooooser will be discover if you added loser
3. now each word has a diverent warn time 2m 5m 1d as you want
4. now you can add as point 3 aktion kick warn tempban permban for realy bad words :-)
6. It can check if somone writs uppercase all the time and warn him if you want
7. you can activate or deactivate bad words
8. or find them in the database with !bwlookup
9.you can once added words update with !bwupdate
10. it can check for players witch write in colors
11. the included sql file includes 249 bad words and it checks for 200000 variations of this words
Installation:
1. copy the file in your eternalplugins folder
2. import sql file to your b3 database
Done
The commands:
To add a bad word
!bwadd arsch german warn 2m ass Wir dulden keine schimpfwörter
!bwadd 1.badword 2.language 3.aktion 4.translationenglish 5.warnmessage
To find a bad word in database
!bwlookup arsch
or
!bwlookup @5
To activate or deaktivate a bad word (deactivate means you dont get warned enymore if you say the word, but its still in db)
!bwactive yes
or
!bwactive no
to update a bad word
!bwupdate arsch german warn 2m ass Wir dulden keine schimpfwörter
!bwupdate 1.badword 2.language 3.aktion 4.translationenglish 5.warnmessage
Please write me what you think about my plugin or report me bugs here is the hole code for those who wanne see it
thebrain.py file
#
# The Brain Plugin for BigBrotherBot
# Copyright (C) 2008 Master_Jochen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# Changelog:
# 0.0.3:
# added better word controll like loooooooooooooooooooser will be discovert too
# bad name warning only comes out in a lower rate
__version__ = '0.0.5'
__author__ = 'Master_Jochen'
import b3, time, threading, re
from b3 import clients
import b3.events
import b3.plugin
import b3.cron
import datetime, string
from b3 import functions
#--------------------------------------------------------------------------------------------------
class ThebrainPlugin(b3.plugin.Plugin):
_rate = None
_cronTab = None
_adminPlugin = None
_fileName = None
_qwwa = ''
_waitforanswer = 'False'
_waitforanswerof = ''
_questionid = 0
_msganswer = ''
_playermessage = ''
_lang = ''
_aktion = ''
_duration = ''
_englishtrans = ''
_warnmsg = ''
_id = 1
_warnmsgbn = 'Change your name or get kicked!'#warn message for bad word
_warnmsguppercase = 'Dont write uppercase!'#warn message for bad word
_duration = '1d' # warnduration
_ask = 0
_countbadwords = 0
_askfast = 0
_badname = False
_msg = ''
_minlevel = 1000
_table = None
_bwcount = 0
_uppercasecheck = 'off'
_maxuppercasetimes = 3
_warnuppercaseduration = '1m'
_active = 'yes'
_tellbadwords = 'off'
_tell_badwords_text = 'I know %(count)s bad words'
def startup(self):
"""\
Initialize plugin settings
"""
global i1
i1 = 1
global i2
i2 = 1
global answerfound
answerfound = 'false'
self._countbw = 0
self._adminPlugin.registerCommand(self, 'bwadd', 28, self.cmd_bwadd)
self._adminPlugin.registerCommand(self, 'bwlookup', 28, self.cmd_bwlookup)
self._adminPlugin.registerCommand(self, 'bwactive', 28, self.cmd_bwactive)
self.query = self.console.storage.query
self.getCounts = self.console.storage.getCounts
# listen for client events
self.registerEvent(b3.events.EVT_CLIENT_SAY)
self.registerEvent(b3.events.EVT_CLIENT_AUTH)
self.registerEvent(b3.events.EVT_CLIENT_TEAM_SAY)
self.registerEvent(b3.events.EVT_CLIENT_PRIVATE_SAY)
#self.console.say('Starting the brain')
def onLoadConfig(self):
self._adminPlugin = self.console.getPlugin('admin')
try:
#self.console.say('try to register crontab !!!')
self._rate = self.config.getint('settings', 'rate')
except:
self.console.say('exeption no rate entered')
self.error('config missing [settings].rate')
return False
try:
self._warnmsg = self.config.get('settings', 'warnmsgbadword')
except:
self.error('config missing [settings].warnmsgbadword')
return False
try:
self._warnmsgbn = self.config.get('settings', 'warnmsgbadname')
except:
self.error('config missing [settings].warnmsgbadname')
return False
try:
self._duration = self.config.get('settings', 'warnduration')
except:
self.error('config missing [settings].warnduration')
return False
try:
self._minlevel = self.config.getint('settings', 'minlevel')
except:
self.error('config missing [settings].minlevel')
return False
try:
self._uppercasecheck = self.config.get('settings', 'uppercaseConttroll')
except:
self.error('config missing [settings].uppercaseConttroll')
return False
try:
self._warnmsguppercase = self.config.get('settings', 'warnmsguppercase')
except:
self.error('config missing [settings].warnmsguppercase')
return False
try:
self._maxuppercasetimes = self.config.getint('settings', 'warn_uppercase_after_times')
except:
self.error('config missing [settings].warn_uppercase_after_times')
return False
try:
self._warnuppercaseduration = self.config.get('settings', 'warn_uppercase_duration')
except:
self.error('config missing [settings].warn_uppercase_duration')
return False
try:
self._tellbadwords = self.config.get('settings', 'tell_badwords_in_db')
except:
self.error('config missing [settings].tell_badwords_in_db')
return False
try:
self._tell_badwords_text = self.config.get('settings', 'tell_badwords_text')
except:
self.error('config missing [settings].tell_badwords_text')
return False
if self._cronTab:
# remove existing crontab
self.console.cron - self._cronTab
self.console.say('removing existing crontab')
if self._rate != 0:
self._cronTab = b3.cron.PluginCronTab(self, self.todo, '*/%s' % self._rate)
self.console.cron + self._cronTab
else:
self.console.say('rate is 0 [****]')
def todo(self):
message = self._tell_badwords_text.replace('$count',str(self._countbw))
if(self._tellbadwords == 'yes'):
self.console.say(message)
self.check()
return True
def cleancolors(self, data):
return self.console.stripColors(data)
def cmd_bwadd(self, data, client, cmd=None):
"""\
1.Badword 2.Language 3.aktion 4.duration 5.englishtranslation 6.warnmessage
(none)
"""
if(self.checkforbadword(data) == True):
cmd.sayLoudOrPM(client, '^1 I allredy know the word ^7%s ^1 found @ ^7%s' % (self._badword, self._id))
return False
#default name of the table for this data object
self._table = 'badwords'
#fields of the table
id = None
input = data.split(' ',5)
#self.console.say('^2%s'% data)
badword = input[0]
lang = input[1]
aktion = input[2]
duration = input[3]
englishtrans = input[4]
warnmsg = input[5]
active = 'yes'
q = 'INSERT INTO %s ( badword, lang, aktion, duration, englishtrans, warnmsg, active ) VALUES (\'%s\',\'%s\', \'%s\',\'%s\',\'%s\', \'%s\', \'%s\')' % (self._table, badword, lang, aktion, duration, englishtrans, warnmsg, active)
cursor = self.query(q)
#self.console.say('^2%s'% q)
cmd.sayLoudOrPM(client, '^1 Thanks for making me smarter, added ^7%s ^1 to the database' % (input[0]))
return
def cmd_bwlookup(self, data, client, cmd=None):
"""\
!lookupbw YourBadWord
(none)
"""
if(data.find('@')!= -1):
data = data.replace('@', '')
data = self.get_Dbinfobyid(data)
if(self.checkforbadword(data) == True):
cmd.sayLoudOrPM(client, '^7%s^2 found @^7%s' % (self._badword, self._id))
cmd.sayLoudOrPM(client, '^2language:^7%s' % (self._lang))
cmd.sayLoudOrPM(client, '^2aktion:^7%s' % (self._aktion))
cmd.sayLoudOrPM(client, '^2duration:^7%s' % (self._duration))
cmd.sayLoudOrPM(client, '^2english translation:^7%s' % (self._englishtrans))
cmd.sayLoudOrPM(client, '^2warn message:^7%s' % (self._warnmsg))
cmd.sayLoudOrPM(client, '^2active:^7%s' % (self._active))
return
def cmd_bwactive(self, data, client, cmd=None):
"""\
!bwactivate @123 yes or !bwactivate badword no
(none)
"""
self._table = 'badwords'
input = data.split(' ',1)
if(input[0].find('@')!= -1):
input[0] = input[0].replace('@', '')
self._id = input[0]
if(input[1] =='yes'):
self._active = 'yes'
else:
self._active = 'no'
q = 'UPDATE %s SET active=\'%s\' WHERE id=%s' % (self._table, self._active, self._id)
else:
self._badword = input[0]
if(input[1] =='yes'):
self._active = 'yes'
else:
self._active = 'no'
q = 'UPDATE %s SET active=\'%s\' WHERE badword=\'%s\'' % (self._table, self._active, self._badword)
#cursor = self.query(q)
self.query(q)
cmd.sayLoudOrPM(client, '^1 Updated ^7%s ^1 is now active %s' % (input[0],input[1]))
return
def check(self):
self.console.clients.sync()
for p in self.console.clients.getList():
name = p.exactName
self.cleancolors(name)
if(self.checkforbadword(name) == True):
self._warnmsg = self._warnmsgbn
self.penalizeClient(event.client)
def onEvent(self, event):
"""\
Handle intercepted events
"""
if not event.client or event.client.cid == None or len(event.data) <= 0:
return
if event.type == b3.events.EVT_CLIENT_SAY:
name = event.client.exactName
self.cleancolors(name)
if(self.checkforbadword(event.data) == True):
self.penalizeClient(event.client)
if(self._uppercasecheck == 'on'):
self.is_uppercase(event.data,event.client)
if(event.client.var(self, 'points').value >= self._maxuppercasetimes):
event.client.setvar(self, 'points', 0)
self._adminPlugin.warnClient(event.client, self._warnmsguppercase, None, True, '', self._warnuppercaseduration)
def penalizeClient(self, client, data=''):
#self.console.say('penalizeClient')
if not client :
return False
#self.console.say('penalizeClient2')
self._msg=('%s %s is ^2%s ^1and means ^2%s'% (self._warnmsg,self._badword,self._lang,self._englishtrans))
#self.console.say('warnmsg: %s'% self._msg)
if(client.maxLevel<self._minlevel):
if(self._aktion == 'warn'):
self._adminPlugin.warnClient(client, self._msg, None, True, '', self._duration)
if(self._aktion == 'kick'):
self.console.kick(client.cid,self._msg, client)
if(self._aktion == 'tempban'):
self.console.tempban(client.cid,self._msg, self._duration, client)
if(self._aktion == 'permban'):
self.console.ban(client.cid, self._msg, client)
def checkforbadword(self, text):
#self.console.say('^checking for bad word')
i1 = 1
i2 = 0
while self.get_Dbinfo('badwords','id',i1) != False:
badworddb = self.get_Dbinfo('badwords','id',i1)
#self.console.say('^checking %s'%badworddb)
if(text.find(badworddb) != -1):
#self.console.say('bad word found ')
self.get_allinfo(badworddb)
return True
#check lower
text = text.lower()
if(text.find(badworddb) != -1):
self.get_allinfo(badworddb)
if(self._active == 'yes'):
return True
#remove spaces or other stuff
text = text.replace(' ', '')
text = text.replace('*', '')
text = text.replace('#', '')
text = text.replace('.', '')
text = text.replace('!', '')
text = text.replace('_', '')
text = text.replace('"', '')
text = text.replace('§', '')
text = text.replace('$', '')
text = text.replace('%', '')
text = text.replace('&', '')
text = text.replace('/', '')
text = text.replace('(', '')
text = text.replace(')', '')
text = text.replace('=', '')
text = text.replace('?', '')
text = text.replace('+', '')
text = text.replace('-', '')
text = text.replace(',', '')
text = text.replace('@', '')
if(text.find(badworddb) != -1):
self.get_allinfo(badworddb)
if(self._active == 'yes'):
return True
text = text.replace('1', 'i')
if(text.find(badworddb) != -1):
self.get_allinfo(badworddb)
if(self._active == 'yes'):
return True
i2= len ( text )
for i in range(1, i2):
text = text.replace('aa', 'a')
text = text.replace('bb', 'b')
text = text.replace('cc', 'c')
text = text.replace('dd', 'd')
text = text.replace('ee', 'e')
text = text.replace('ff', 'f')
text = text.replace('gg', 'g')
text = text.replace('hh', 'h')
text = text.replace('ii', 'i')
text = text.replace('jj', 'j')
text = text.replace('kk', 'k')
text = text.replace('ll', 'l')
text = text.replace('mm', 'm')
text = text.replace('nn', 'n')
text = text.replace('oo', 'o')
text = text.replace('pp', 'p')
text = text.replace('qq', 'q')
text = text.replace('rr', 'r')
text = text.replace('ss', 's')
text = text.replace('tt', 't')
text = text.replace('uu', 'u')
text = text.replace('vv', 'v')
text = text.replace('ww', 'w')
text = text.replace('xx', 'x')
text = text.replace('yy', 'y')
text = text.replace('zz', 'z')
if(text.find(badworddb) != -1):
self.get_allinfo(badworddb)
if(self._active == 'yes'):
return True
if(self._countbw<i1):
self._countbw = i1
i1 = i1 + 1
return False
def cleanlower(self, data):
return re.sub(self._reClean, ' ', self.console.stripColors(data.lower()))
def get_allinfo(self, badword):
#self.console.say('gathering more info about the word')
q = 'SELECT * from badwords WHERE badword = "%s" LIMIT 1' % (badword)
cursor = self.query(q)
if (cursor and (cursor.rowcount > 0) ):
r = cursor.getRow()
self._id = r['id']
self._lang = r['lang']
self._aktion = r['aktion']
self._duration = r['duration']
self._englishtrans = r['englishtrans']
self._warnmsg = r['warnmsg']
self._badword = r['badword']
self._active = r['active']
#self.console.say('gathered more info about the word-return true')
return True
else:
return False
def is_uppercase(self,text,client):
points = 0
if not client.isvar(self, 'points'):
client.setvar(self, 'points', 0)
else:
points = client.var(self, 'points').value
if (text.upper() == text):
points = client.var(self, 'points').value
points = points + 1
client.setvar(self, 'points', points)
return points
else:
return points
def get_Dbinfo(self, tabel, searchfield, searchfor):
q = 'SELECT * from %s WHERE %s = "%s" LIMIT 1' % (tabel, searchfield, searchfor)
cursor = self.query(q)
if (cursor and (cursor.rowcount > 0) and (not cursor.EOF) ):
r = cursor.getRow()
info = r['badword']
cursor.close()
return info
else:
cursor.close()
return False
def get_Dbinfobyid(self,id):
tabel = 'badwords'
searchfield = 'id'
searchfor = id
q = 'SELECT * from %s WHERE %s = "%s" LIMIT 1' % (tabel, searchfield, searchfor)
cursor = self.query(q)
if (cursor and (cursor.rowcount > 0) and (not cursor.EOF) ):
r = cursor.getRow()
info = r['badword']
cursor.close()
return info
else:
cursor.close()
return False
and here plugin_thebrain.xml file
<configuration plugin="thebrain">
<settings name="settings">
<set name="rate">10</set>
<set name="warnmsgbadword">Watch your Tone!</set>
<set name="warnmsgbadname">Change your name or get kicked</set>
<set name="warnduration">2m</set>
<set name="minlevel">24</set>
<set name="tell_badwords_in_db">yes</set>
<set name="tell_badwords_text">^1 I know no ^3 $count bad words</set>
<set name="uppercaseConttroll">on</set>
<set name="warnmsguppercase">Dont write uppercase all the time!</set>
<set name="warn_uppercase_after_times">3</set>
<set name="warn_uppercase_duration">2m</set>
</settings>
</configuration>