fulvia/modules/admin.py

101 lines
2.3 KiB
Python
Raw Permalink Normal View History

2018-03-16 03:13:43 -04:00
#!/usr/bin/env python3
"""
Some administrative functions relating to the bot.
"""
import module
@module.require_admin
@module.commands('join')
@module.example('.join #example or .join #example key')
def join(bot, trigger):
"""Join the specified channel. This is an admin-only command."""
2020-01-07 18:58:19 -05:00
channel = trigger.args[1] if len(trigger.args) >= 2 else None
key = trigger.args[2] if len(trigger.args) >= 3 else None
2018-03-16 03:13:43 -04:00
if not channel:
return
elif not key:
bot.join(channel)
else:
bot.join(channel, key)
@module.require_admin
@module.commands('part')
@module.example('.part #example')
def part(bot, trigger):
"""Part the specified channel. This is an admin-only command."""
2020-01-07 18:58:19 -05:00
if len(trigger.args) < 2:
return
channel = trigger.args[1]
if len(trigger.args) >= 3:
part_msg = ' '.join(trigger.args[2:])
else:
part_msg = None
if not channel.startswith("#"):
part_msg = channel
channel = ""
2018-03-16 03:13:43 -04:00
if not channel:
channel = trigger.channel
if part_msg:
bot.part(channel, part_msg)
else:
bot.part(channel)
@module.require_owner
@module.commands('quit')
def quit(bot, trigger):
"""Quit from the server. This is an owner-only command."""
2020-01-07 18:58:19 -05:00
if len(trigger.args) >= 2:
quit_message = ' '.join(trigger.args[1:])
else:
2018-03-16 03:13:43 -04:00
quit_message = f"Quitting on command from {trigger.nick}"
bot.quit(quit_message)
@module.require_admin
@module.commands('msg')
@module.example('.msg #YourPants Does anyone else smell neurotoxin?')
def msg(bot, trigger):
"""
Send a message to a given channel or nick. Can only be done by an admin.
"""
2020-01-07 18:58:19 -05:00
if len(trigger.args) < 3:
2018-03-16 03:13:43 -04:00
return
2020-01-07 18:58:19 -05:00
channel = trigger.args[1]
message = ' '.join(trigger.args[2:])
2018-03-16 03:13:43 -04:00
bot.msg(channel, message)
@module.require_admin
@module.commands('me')
@module.example(".me #erp notices your bulge")
def me(bot, trigger):
"""
Send an ACTION (/me) to a given channel or nick. Can only be done by an
admin.
"""
2020-01-07 18:58:19 -05:00
if len(trigger.args) < 3:
2018-03-16 03:13:43 -04:00
return
2020-01-07 18:58:19 -05:00
channel = trigger.args[1]
action = ' '.join(trigger.args[2:])
2018-03-16 03:13:43 -04:00
# msg = '\x01ACTION %s\x01' % action
bot.describe(channel, action)
@module.require_admin
@module.commands('selfmode')
@module.example(".mode +B")
def self_mode(bot, trigger):
"""Set a user mode on Fulvia. Can only be done in privmsg by an admin."""
2020-01-07 18:58:19 -05:00
if len(trigger.args) < 2:
return
mode = trigger.args[1]
2018-03-16 03:13:43 -04:00
add_mode = mode.startswith("+")
bot.mode(bot.nickname, add_mode, mode)