2013-04-28 10:08:01 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""
|
|
|
|
chop.py - Phenny Channel Administration Module
|
2014-06-21 23:33:37 +02:00
|
|
|
Copyright 2013, sfan5
|
2013-04-28 10:08:01 +02:00
|
|
|
"""
|
2013-04-28 20:47:21 +02:00
|
|
|
import os, web, re
|
|
|
|
|
|
|
|
chop = {}
|
|
|
|
chop["badword_limit"] = 4
|
2014-06-22 12:46:49 +02:00
|
|
|
chop["badword_enabled"] = False
|
2014-06-21 23:33:37 +02:00
|
|
|
chop["badword_kickmsg"] = "Chop!" # "Stop using bad words!"
|
2013-04-28 20:47:21 +02:00
|
|
|
chop["victims"] = {} # for future use
|
2014-06-22 12:10:56 +02:00
|
|
|
badword_list = "" # TODO: Get badword list from somewhere
|
2013-04-28 20:47:21 +02:00
|
|
|
|
|
|
|
def num_badwords(sentence):
|
|
|
|
badwords = 0
|
|
|
|
for bwl in badword_list.split("\n"):
|
2013-04-28 21:38:09 +02:00
|
|
|
args = bwl.split(" ")
|
|
|
|
if len(args) < 2: continue
|
2013-04-28 21:58:01 +02:00
|
|
|
arg = ' '.join(args[1:]).rstrip("\n\r")
|
2013-04-28 21:48:28 +02:00
|
|
|
if args[0] == "regex":
|
|
|
|
try:
|
|
|
|
rgx = re.compile(arg)
|
|
|
|
except Exception as e:
|
|
|
|
print("Error while compiling regex ''%s'': %s" % (arg, str(e)))
|
|
|
|
continue
|
2013-04-28 20:47:21 +02:00
|
|
|
for word in sentence.split(" "):
|
2013-04-28 21:29:31 +02:00
|
|
|
word = word.rstrip(",.;:")
|
|
|
|
word = word.lstrip(",.;:")
|
2013-04-28 21:38:09 +02:00
|
|
|
if args[0] == "raw":
|
|
|
|
if word.lower() == arg.lower():
|
2013-04-28 20:47:21 +02:00
|
|
|
badwords += 1
|
2013-04-28 21:38:09 +02:00
|
|
|
elif args[0] == "regex":
|
2013-04-28 20:47:21 +02:00
|
|
|
if not rgx.match(word) == None:
|
|
|
|
badwords += 1
|
2013-04-28 21:38:09 +02:00
|
|
|
if args[0] == "regex": del rgx
|
2014-06-21 23:33:37 +02:00
|
|
|
|
2013-04-28 20:47:21 +02:00
|
|
|
return badwords
|
2013-04-28 10:08:01 +02:00
|
|
|
|
2013-05-11 08:00:16 +02:00
|
|
|
def hmasktrans(va):
|
|
|
|
a = "!" in va
|
|
|
|
b = "@" in va
|
|
|
|
if not a and not b:
|
2014-06-21 23:33:37 +02:00
|
|
|
return va + "!*@*"
|
2013-05-11 08:00:16 +02:00
|
|
|
elif a and not b:
|
|
|
|
return va + "@*"
|
|
|
|
elif not a and b:
|
|
|
|
return "*!" + va
|
|
|
|
else: # a and b
|
|
|
|
return va
|
|
|
|
|
|
|
|
def chanmodefunc(phenny, input, mode, modfunc=None):
|
|
|
|
if modfunc == None:
|
|
|
|
modfunc = lambda x: x
|
2013-04-28 10:08:01 +02:00
|
|
|
arg = input.group(2)
|
2013-05-11 08:00:16 +02:00
|
|
|
if not arg: return phenny.write(['MODE', input.sender, mode, input.nick], "")
|
2013-04-28 10:08:01 +02:00
|
|
|
arg = arg.split(" ")
|
2013-05-11 08:00:16 +02:00
|
|
|
skip_next = False
|
|
|
|
for i in range(0, len(arg)):
|
|
|
|
if skip_next:
|
|
|
|
skip_next = False
|
|
|
|
continue
|
|
|
|
va = arg[i]
|
|
|
|
if va.startswith('#'):
|
|
|
|
if i+2 > len(arg): return phenny.reply("Too few arguments")
|
|
|
|
phenny.write(['MODE', va, mode, modfunc(arg[i+1])], "")
|
|
|
|
skip_next = True
|
|
|
|
continue
|
|
|
|
phenny.write(['MODE', input.sender, mode, modfunc(va)], "")
|
|
|
|
|
|
|
|
def voice(phenny, input):
|
|
|
|
if not input.admin: return
|
|
|
|
chanmodefunc(phenny, input, '+v')
|
2013-04-28 10:08:01 +02:00
|
|
|
|
|
|
|
voice.commands = ['voice']
|
|
|
|
|
|
|
|
def devoice(phenny, input):
|
|
|
|
if not input.admin: return
|
2013-05-11 08:00:16 +02:00
|
|
|
chanmodefunc(phenny, input, '-v')
|
2013-04-28 10:08:01 +02:00
|
|
|
|
|
|
|
devoice.commands = ['devoice']
|
|
|
|
|
2014-06-21 23:33:37 +02:00
|
|
|
def op(phenny, input):
|
2013-04-28 10:08:01 +02:00
|
|
|
if not input.admin: return
|
2014-06-21 23:33:37 +02:00
|
|
|
chanmodefunc(phenny, input, '+o')
|
2013-04-28 10:08:01 +02:00
|
|
|
|
2014-06-21 23:33:37 +02:00
|
|
|
op.commands = ['op']
|
|
|
|
|
|
|
|
def deop(phenny, input):
|
|
|
|
if not input.admin: return
|
|
|
|
chanmodefunc(phenny, input, '-o')
|
|
|
|
|
|
|
|
deop.commands = ['deop']
|
2013-04-28 10:08:01 +02:00
|
|
|
|
|
|
|
def ban(phenny, input):
|
|
|
|
if not input.admin: return
|
2013-05-11 08:00:16 +02:00
|
|
|
chanmodefunc(phenny, input, '+b', hmasktrans)
|
2013-04-28 10:08:01 +02:00
|
|
|
|
|
|
|
ban.commands = ['ban']
|
|
|
|
|
|
|
|
def unban(phenny, input):
|
|
|
|
if not input.admin: return
|
2013-05-11 08:00:16 +02:00
|
|
|
chanmodefunc(phenny, input, '-b', hmasktrans)
|
2013-04-28 10:08:01 +02:00
|
|
|
|
|
|
|
unban.commands = ['unban']
|
2013-04-28 20:47:21 +02:00
|
|
|
|
2013-05-01 11:24:26 +02:00
|
|
|
def mute(phenny, input):
|
|
|
|
if not input.admin: return
|
2013-05-11 08:00:16 +02:00
|
|
|
chanmodefunc(phenny, input, '+q', hmasktrans)
|
2013-05-01 11:24:26 +02:00
|
|
|
|
|
|
|
mute.commands = ['mute']
|
|
|
|
|
|
|
|
def unmute(phenny, input):
|
|
|
|
if not input.admin: return
|
2013-05-11 08:00:16 +02:00
|
|
|
chanmodefunc(phenny, input, '-q', hmasktrans)
|
2013-05-01 11:24:26 +02:00
|
|
|
|
|
|
|
unmute.commands = ['unmute']
|
|
|
|
|
2014-06-21 23:33:37 +02:00
|
|
|
def kick(phenny, input):
|
2013-04-28 20:47:21 +02:00
|
|
|
if not input.admin: return
|
2014-06-21 23:33:37 +02:00
|
|
|
arg = input.group(2)
|
|
|
|
if not arg: return
|
|
|
|
arg = arg.split(" ")
|
|
|
|
if len(arg) < 1: return
|
|
|
|
if len(arg) == 1:
|
|
|
|
arg.append("")
|
|
|
|
if arg[0].startswith('#'):
|
|
|
|
if len(arg) < 2: return
|
|
|
|
phenny.write(['KICK', arg[0], arg[1]], ' '.join(arg[2:]))
|
|
|
|
else:
|
|
|
|
phenny.write(['KICK', input.sender, arg[0]], ' '.join(arg[1:]))
|
2013-04-28 20:47:21 +02:00
|
|
|
|
2014-06-21 23:33:37 +02:00
|
|
|
kick.commands = ['kick']
|
2013-04-28 20:47:21 +02:00
|
|
|
|
|
|
|
def badword_watcher(phenny, input):
|
|
|
|
if not input.sender.startswith('#'): return
|
|
|
|
if not chop["badword_enabled"]: return
|
|
|
|
bwc = num_badwords(input.group(0))
|
|
|
|
if bwc > chop["badword_limit"]:
|
2014-06-21 23:33:37 +02:00
|
|
|
phenny.write(['KICK', input.sender, input.nick], chop["badword_kickmsg"])
|
2013-04-28 20:47:21 +02:00
|
|
|
try:
|
|
|
|
chop["victims"][input.nick] += 1
|
|
|
|
except:
|
|
|
|
chop["victims"][input.nick] = 1
|
|
|
|
|
|
|
|
badword_watcher.priority = 'high'
|
|
|
|
badword_watcher.rule = r'.*'
|
2014-06-22 12:46:49 +02:00
|
|
|
badword_watcher.nohook = True
|
2013-04-28 20:47:21 +02:00
|
|
|
|
|
|
|
def badword_ctrl(phenny, input):
|
|
|
|
if not input.admin: return
|
|
|
|
arg = input.group(2)
|
|
|
|
if not arg: return
|
|
|
|
if arg == "enable" or arg == "on":
|
|
|
|
chop["badword_enabled"] = True
|
2013-04-28 22:21:01 +02:00
|
|
|
phenny.say("done.")
|
2013-04-28 20:47:21 +02:00
|
|
|
elif arg == "disable" or arg == "off":
|
|
|
|
chop["badword_enabled"] = False
|
2013-04-28 22:21:01 +02:00
|
|
|
phenny.say("done.")
|
2013-04-28 21:29:31 +02:00
|
|
|
elif arg == "reload":
|
2014-06-21 23:33:37 +02:00
|
|
|
badword_list = "" # TODO: Get badword list from somewhere
|
2013-04-28 22:21:01 +02:00
|
|
|
phenny.say("done.")
|
2013-04-28 20:47:21 +02:00
|
|
|
|
|
|
|
badword_ctrl.commands = ['badword']
|