fulvia/modules/adminchannel.py
2020-01-08 07:51:00 -05:00

117 lines
3.4 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Some administrative functions relating to the channel the bot is in. Note
that most of these will require the bot to have admin privileges in the
channel.
"""
import re
import module
from tools import op_level, configureHostMask
op = ['~', '!', '@', '%']
@module.require_chanmsg
@module.require_admin
@module.commands('kick')
@module.example(".kick Rob It's time to stop.")
def kick(bot, trigger):
"""
Kick a user from the channel.
"""
if bot.channels[trigger.channel].users[bot.nick].op_level not in op:
return bot.reply("I'm not a channel operator!")
if len(trigger.args) < 2:
return bot.reply("Who do you want me to kick?")
target = trigger.args[1]
if len(trigger.args) >= 3:
reason = ' '.join(trigger.args[2:])
else:
reason = "Stop doing the bad."
if target == bot.nick:
return bot.reply("I can't let you do that.")
bot.kick(trigger.channel, target, reason)
@module.require_chanmsg
@module.require_admin
@module.commands('ban')
@module.example(".ban Rob")
def ban(bot, trigger):
"""
This give admins the ability to ban a user.
The bot must be a Channel Operator for this command to work.
"""
if bot.channels[trigger.channel].users[bot.nick].op_level not in op:
return bot.reply("I'm not a channel operator!")
if len(trigger.args) < 2:
return bot.reply("Who do you want me to ban?")
banmask = configureHostMask(trigger.args[1])
bot.mode(trigger.channel, True, "b", mask=banmask)
@module.require_chanmsg
@module.require_admin
@module.commands('unban')
@module.example(".unban Rob")
def unban(bot, trigger):
"""
This give admins the ability to unban a user.
The bot must be a Channel Operator for this command to work.
"""
if bot.channels[trigger.channel].users[bot.nick].op_level not in op:
return bot.reply("I'm not a channel operator!")
if len(trigger.args) < 2:
return bot.reply("Who do you want me to ban?")
banmask = configureHostMask(trigger.args[1])
bot.mode(trigger.channel, False, "b", mask=banmask)
@module.require_chanmsg
@module.require_admin
@module.commands('kickban')
@module.example(".kickban Rob It's time to stop.")
def kickban(bot, trigger):
"""
This gives admins the ability to kickban a user.
The bot must be a Channel Operator for this command to work.
.kickban [#chan] user1 user!*@module.* get out of here
"""
if bot.channels[trigger.channel].users[bot.nick].op_level not in op:
return bot.reply("I'm not a channel operator!")
if len(trigger.args) < 2:
return bot.reply("Who do you want me to ban?")
target = trigger.args[1]
if len(trigger.args) >= 3:
reason = ' '.join(trigger.args[2:])
else:
reason = "Stop doing the bad."
if target == bot.nick:
return bot.reply("I can't let you do that.")
banmask = configureHostMask(trigger.args[1])
bot.mode(trigger.channel, False, "b", mask=banmask)
bot.kick(trigger.channel, target, reason)
@module.require_chanmsg
@module.require_admin
@module.commands('settopic')
@module.example(".settopic We're discussing penises, would you like to join?")
def settopic(bot, trigger):
"""
This gives ops the ability to change the topic.
The bot must be a Channel Operator for this command to work.
"""
if bot.channels[trigger.channel].users[bot.nick].op_level not in op:
return bot.reply("I'm not a channel operator!")
if len(trigger.args) < 2:
return bot.reply("What do you want the topic set to?")
bot.topic(trigger.channel, ' '.join(trigger.args[1:]))