mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 09:19:23 +01:00
d9db7e1b9e
- Move config handling into separate module - Implement identify and status commands, currently only supporting the admin account defined in the config. Closes #1. - Move proto.add_cmd to utils.py, rename _msg() to msg() - Allow sending the command name as an optional argument in add_cmd - Add catch-all exception handling in plugins to prevent them from crashing the program!
29 lines
765 B
Python
29 lines
765 B
Python
import string
|
|
import proto
|
|
|
|
global bot_commands
|
|
# This should be a mapping of command names to functions
|
|
bot_commands = {}
|
|
|
|
# From http://www.inspircd.org/wiki/Modules/spanningtree/UUIDs.html
|
|
chars = string.digits + string.ascii_uppercase
|
|
iters = [iter(chars) for _ in range(6)]
|
|
a = [next(i) for i in iters]
|
|
|
|
def next_uid(sid, level=-1):
|
|
try:
|
|
a[level] = next(iters[level])
|
|
return sid + ''.join(a)
|
|
except StopIteration:
|
|
return UID(level-1)
|
|
|
|
def msg(irc, target, text, notice=False):
|
|
command = 'NOTICE' if notice else 'PRIVMSG'
|
|
proto._sendFromUser(irc, '%s %s :%s' % (command, target, text))
|
|
|
|
def add_cmd(func, name=None):
|
|
if name is None:
|
|
name = func.__name__
|
|
name = name.lower()
|
|
bot_commands[name] = func
|