fulvia/trigger.py
2022-10-29 19:25:12 -04:00

62 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python3
"""
The trigger abstraction layer.
"""
import config
def split_user(user):
"""
Splits a user hostmask into <nick>!<ident>@<host>
"""
nick, _, host = user.partition("!")
ident, _, host = host.partition("@")
if not host:
host = ident
ident = ""
return nick, ident, host
class Trigger():
def __init__(self, user, channel, message):
self.channel = channel
"""
The channel from which the message was sent.
In a private message, this is the nick that sent the message.
"""
self.is_privmsg = not channel.startswith("#")
"""True if the trigger is from a user, False if it's from a channel."""
self.hostmask = user
"""
Entire hostmask of the person who sent the message.
eg. <nick>!<ident>@<host>
"""
nick, ident, host = split_user(user)
self.nick = nick
"""Nick of person who sent the message."""
self.ident = ident
self.user = ident
"""Local username (AKA ident) of the person who sent the message."""
self.host = host
"""The hostname of the person who sent the message"""
self.args = message.strip().split(' ')
"""Pseudo-ARGV for a bot command."""
self.msg = message
"""Retain the original message."""
admins = config.admins + [config.owner]
self.admin = any([user == admin for admin in admins])
"""
True if the user which triggered the command is one of the bot's
admins.
"""
self.owner = user == config.owner
"""True if the nick which triggered the command is the bot's owner."""