[ChOp] Reorganize, clean up and modify stuff
This commit is contained in:
parent
275c4bbe6c
commit
7365f3a398
95
chop.py
95
chop.py
@ -1,15 +1,16 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
"""
|
"""
|
||||||
chop.py - Phenny Channel Administration Module
|
chop.py - Phenny Channel Administration Module
|
||||||
Copyright 2013, Sfan5
|
Copyright 2013, sfan5
|
||||||
"""
|
"""
|
||||||
import os, web, re
|
import os, web, re
|
||||||
|
|
||||||
chop = {}
|
chop = {}
|
||||||
chop["badword_limit"] = 4
|
chop["badword_limit"] = 4
|
||||||
chop["badword_enabled"] = True
|
chop["badword_enabled"] = True
|
||||||
|
chop["badword_kickmsg"] = "Chop!" # "Stop using bad words!"
|
||||||
chop["victims"] = {} # for future use
|
chop["victims"] = {} # for future use
|
||||||
badword_list = ""#web.get("http://sfan5.minetest.net/badwords.txt")
|
badword_list = ""
|
||||||
|
|
||||||
def num_badwords(sentence):
|
def num_badwords(sentence):
|
||||||
badwords = 0
|
badwords = 0
|
||||||
@ -33,14 +34,14 @@ def num_badwords(sentence):
|
|||||||
if not rgx.match(word) == None:
|
if not rgx.match(word) == None:
|
||||||
badwords += 1
|
badwords += 1
|
||||||
if args[0] == "regex": del rgx
|
if args[0] == "regex": del rgx
|
||||||
|
|
||||||
return badwords
|
return badwords
|
||||||
|
|
||||||
def hmasktrans(va):
|
def hmasktrans(va):
|
||||||
a = "!" in va
|
a = "!" in va
|
||||||
b = "@" in va
|
b = "@" in va
|
||||||
if not a and not b:
|
if not a and not b:
|
||||||
return va + "*!*@*"
|
return va + "!*@*"
|
||||||
elif a and not b:
|
elif a and not b:
|
||||||
return va + "@*"
|
return va + "@*"
|
||||||
elif not a and b:
|
elif not a and b:
|
||||||
@ -48,7 +49,6 @@ def hmasktrans(va):
|
|||||||
else: # a and b
|
else: # a and b
|
||||||
return va
|
return va
|
||||||
|
|
||||||
|
|
||||||
def chanmodefunc(phenny, input, mode, modfunc=None):
|
def chanmodefunc(phenny, input, mode, modfunc=None):
|
||||||
if modfunc == None:
|
if modfunc == None:
|
||||||
modfunc = lambda x: x
|
modfunc = lambda x: x
|
||||||
@ -70,21 +70,54 @@ def chanmodefunc(phenny, input, mode, modfunc=None):
|
|||||||
|
|
||||||
def voice(phenny, input):
|
def voice(phenny, input):
|
||||||
if not input.admin: return
|
if not input.admin: return
|
||||||
# Can only be done by an admin
|
|
||||||
chanmodefunc(phenny, input, '+v')
|
chanmodefunc(phenny, input, '+v')
|
||||||
|
|
||||||
voice.commands = ['voice']
|
voice.commands = ['voice']
|
||||||
|
|
||||||
def devoice(phenny, input):
|
def devoice(phenny, input):
|
||||||
if not input.admin: return
|
if not input.admin: return
|
||||||
# Can only be done by an admin
|
|
||||||
chanmodefunc(phenny, input, '-v')
|
chanmodefunc(phenny, input, '-v')
|
||||||
|
|
||||||
devoice.commands = ['devoice']
|
devoice.commands = ['devoice']
|
||||||
|
|
||||||
|
def op(phenny, input):
|
||||||
|
if not input.admin: return
|
||||||
|
chanmodefunc(phenny, input, '+o')
|
||||||
|
|
||||||
|
op.commands = ['op']
|
||||||
|
|
||||||
|
def deop(phenny, input):
|
||||||
|
if not input.admin: return
|
||||||
|
chanmodefunc(phenny, input, '-o')
|
||||||
|
|
||||||
|
deop.commands = ['deop']
|
||||||
|
|
||||||
|
def ban(phenny, input):
|
||||||
|
if not input.admin: return
|
||||||
|
chanmodefunc(phenny, input, '+b', hmasktrans)
|
||||||
|
|
||||||
|
ban.commands = ['ban']
|
||||||
|
|
||||||
|
def unban(phenny, input):
|
||||||
|
if not input.admin: return
|
||||||
|
chanmodefunc(phenny, input, '-b', hmasktrans)
|
||||||
|
|
||||||
|
unban.commands = ['unban']
|
||||||
|
|
||||||
|
def mute(phenny, input):
|
||||||
|
if not input.admin: return
|
||||||
|
chanmodefunc(phenny, input, '+q', hmasktrans)
|
||||||
|
|
||||||
|
mute.commands = ['mute']
|
||||||
|
|
||||||
|
def unmute(phenny, input):
|
||||||
|
if not input.admin: return
|
||||||
|
chanmodefunc(phenny, input, '-q', hmasktrans)
|
||||||
|
|
||||||
|
unmute.commands = ['unmute']
|
||||||
|
|
||||||
def kick(phenny, input):
|
def kick(phenny, input):
|
||||||
if not input.admin: return
|
if not input.admin: return
|
||||||
# Can only be done by an admin
|
|
||||||
arg = input.group(2)
|
arg = input.group(2)
|
||||||
if not arg: return
|
if not arg: return
|
||||||
arg = arg.split(" ")
|
arg = arg.split(" ")
|
||||||
@ -99,54 +132,12 @@ def kick(phenny, input):
|
|||||||
|
|
||||||
kick.commands = ['kick']
|
kick.commands = ['kick']
|
||||||
|
|
||||||
def ban(phenny, input):
|
|
||||||
if not input.admin: return
|
|
||||||
# Can only be done by an admin
|
|
||||||
chanmodefunc(phenny, input, '+b', hmasktrans)
|
|
||||||
|
|
||||||
ban.commands = ['ban']
|
|
||||||
|
|
||||||
def unban(phenny, input):
|
|
||||||
if not input.admin: return
|
|
||||||
# Can only be done by an admin
|
|
||||||
chanmodefunc(phenny, input, '-b', hmasktrans)
|
|
||||||
|
|
||||||
unban.commands = ['unban']
|
|
||||||
|
|
||||||
def mute(phenny, input):
|
|
||||||
if not input.admin: return
|
|
||||||
# Can only be done by an admin
|
|
||||||
chanmodefunc(phenny, input, '+q', hmasktrans)
|
|
||||||
|
|
||||||
mute.commands = ['mute']
|
|
||||||
|
|
||||||
def unmute(phenny, input):
|
|
||||||
if not input.admin: return
|
|
||||||
# Can only be done by an admin
|
|
||||||
chanmodefunc(phenny, input, '-q', hmasktrans)
|
|
||||||
|
|
||||||
unmute.commands = ['unmute']
|
|
||||||
|
|
||||||
def op(phenny, input):
|
|
||||||
if not input.admin: return
|
|
||||||
# Can only be done by an admin
|
|
||||||
chanmodefunc(phenny, input, '+o')
|
|
||||||
|
|
||||||
op.commands = ['op']
|
|
||||||
|
|
||||||
def deop(phenny, input):
|
|
||||||
if not input.admin: return
|
|
||||||
# Can only be done by an admin
|
|
||||||
chanmodefunc(phenny, input, '-o')
|
|
||||||
|
|
||||||
deop.commands = ['deop']
|
|
||||||
|
|
||||||
def badword_watcher(phenny, input):
|
def badword_watcher(phenny, input):
|
||||||
if not input.sender.startswith('#'): return
|
if not input.sender.startswith('#'): return
|
||||||
if not chop["badword_enabled"]: return
|
if not chop["badword_enabled"]: return
|
||||||
bwc = num_badwords(input.group(0))
|
bwc = num_badwords(input.group(0))
|
||||||
if bwc > chop["badword_limit"]:
|
if bwc > chop["badword_limit"]:
|
||||||
phenny.write(['KICK', input.sender, input.nick], "CHOP!") #"Stop using badwords!")
|
phenny.write(['KICK', input.sender, input.nick], chop["badword_kickmsg"])
|
||||||
try:
|
try:
|
||||||
chop["victims"][input.nick] += 1
|
chop["victims"][input.nick] += 1
|
||||||
except:
|
except:
|
||||||
@ -166,7 +157,7 @@ def badword_ctrl(phenny, input):
|
|||||||
chop["badword_enabled"] = False
|
chop["badword_enabled"] = False
|
||||||
phenny.say("done.")
|
phenny.say("done.")
|
||||||
elif arg == "reload":
|
elif arg == "reload":
|
||||||
badword_list = web.get("http://sfan5.minetest.net/badwords.txt")
|
badword_list = "" # TODO: Get badword list from somewhere
|
||||||
phenny.say("done.")
|
phenny.say("done.")
|
||||||
|
|
||||||
badword_ctrl.commands = ['badword']
|
badword_ctrl.commands = ['badword']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user