fulvia/trigger.py

62 lines
1.5 KiB
Python
Raw Normal View History

2018-03-16 03:13:43 -04:00
#!/usr/bin/env python3
"""
The trigger abstraction layer.
"""
2019-10-08 12:39:13 -04:00
import config
2018-03-16 03:13:43 -04:00
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():
2020-01-07 18:58:19 -05:00
def __init__(self, user, channel, message):
2018-03-16 03:13:43 -04:00
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"""
2020-01-07 18:58:19 -05:00
self.args = message.strip().split(' ')
"""Pseudo-ARGV for a bot command."""
2018-03-16 03:13:43 -04:00
2022-10-29 19:25:12 -04:00
self.msg = message
"""Retain the original message."""
2019-10-08 12:39:13 -04:00
admins = config.admins + [config.owner]
2020-01-07 18:58:19 -05:00
self.admin = any([user == admin for admin in admins])
2018-03-16 03:13:43 -04:00
"""
2020-01-07 18:58:19 -05:00
True if the user which triggered the command is one of the bot's
2018-03-16 03:13:43 -04:00
admins.
"""
2020-01-07 18:58:19 -05:00
self.owner = user == config.owner
2018-03-16 03:13:43 -04:00
"""True if the nick which triggered the command is the bot's owner."""