Ignore bot nicks, add more initial channels, ignore http urls. closes 1, closes 2
This commit is contained in:
parent
f62d4c9f5a
commit
60b9d611a4
21
tallybot.py
21
tallybot.py
|
@ -9,10 +9,21 @@ from collections import defaultdict
|
|||
import sqlite3
|
||||
|
||||
INITIAL_CHANNELS = [
|
||||
'#meta',
|
||||
'#team',
|
||||
'#bots',
|
||||
'#_'
|
||||
]
|
||||
|
||||
OTHER_BOTS = [
|
||||
'NormalHuman555',
|
||||
'zaphod',
|
||||
'cirno',
|
||||
'dustbotoBabilibot',
|
||||
'minerbot2',
|
||||
'sotdbot'
|
||||
]
|
||||
|
||||
def setup_db(path):
|
||||
db_connection = sqlite3.connect(path, isolation_level=None)
|
||||
cur = db_connection.cursor()
|
||||
|
@ -55,12 +66,16 @@ def summarize(message, cursor):
|
|||
def recognize_inc_expr(message):
|
||||
valid_exprs = ['--', '++']
|
||||
if message.type == 'PRIVMSG':
|
||||
# Ignore 'https?://', tildegit.org/delucks/tallybot/issues/2
|
||||
if 'http://' in message.message or 'https://' in message.message:
|
||||
return False
|
||||
for expr in valid_exprs:
|
||||
if expr in message.message:
|
||||
# Only allow incr/decr for messages that have a space AFTER the operator, or messages that end in ++/--
|
||||
if expr+' ' in message.message or message.message.endswith(expr):
|
||||
return True
|
||||
return False
|
||||
|
||||
bot = Bot('karmabot', builtin_prefix='karmabot: ', use_builtin=True, connect_wait=5, initial_channels=INITIAL_CHANNELS)
|
||||
bot = Bot('karmabot', builtin_prefix='karmabot: ', use_builtin=True, connect_wait=5, initial_channels=INITIAL_CHANNELS, ignore={'nicks': OTHER_BOTS})
|
||||
DBFILE = 'tallies.sqlite3'
|
||||
db, cursor = setup_db(DBFILE)
|
||||
|
||||
|
@ -98,7 +113,7 @@ def increment(message):
|
|||
topic = None
|
||||
for expr in valid_exprs:
|
||||
if expr in message.message:
|
||||
topic = message.message.split(expr)[0]
|
||||
topic = message.message.split(expr)[0].strip()
|
||||
if valid_exprs[expr]:
|
||||
vote_up(topic, cursor)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue