39 lines
968 B
Python
39 lines
968 B
Python
|
import string
|
||
|
from bot import IRCLine
|
||
|
BOT = None
|
||
|
|
||
|
def respond(event,msg,prefix=True):
|
||
|
if not BOT: return
|
||
|
is_channel = event.target.startswith("#")
|
||
|
if prefix:
|
||
|
if is_channel:
|
||
|
prefix = f"{event.hostmask.nick}: "
|
||
|
else:
|
||
|
prefix = ""
|
||
|
else:
|
||
|
prefix = ""
|
||
|
target = event.target if is_channel else event.hostmask.nick
|
||
|
BOT.socket.send(IRCLine("PRIVMSG",[target,":"+prefix+msg]))
|
||
|
|
||
|
DELETE_PUNC = str.maketrans(string.punctuation,"\x01"*len(string.punctuation))
|
||
|
|
||
|
OVERRIDES = {"email":"kmail"}
|
||
|
|
||
|
def kdeify(s):
|
||
|
s = s.translate(DELETE_PUNC).replace("\x01","").lower()
|
||
|
if s in OVERRIDES: return OVERRIDES[s]
|
||
|
if s[0]=="c": return "k"+s[1:]
|
||
|
else: return "k"+s
|
||
|
|
||
|
def on_command_kdeify(event):
|
||
|
if not BOT: return None
|
||
|
if len(event.parts)!=1:
|
||
|
respond(event,f"Usage: {BOT.prefix}kdeify <word>")
|
||
|
return
|
||
|
respond(event,"You mean \"{}\"?".format(kdeify(event.parts[0])))
|
||
|
|
||
|
def register(bot):
|
||
|
global BOT
|
||
|
BOT=bot
|
||
|
bot.event_manager.on("command_kdeify",on_command_kdeify)
|