2018-03-16 03:13:43 -04:00
|
|
|
#!/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
|
|
|
|
|
2019-10-08 11:45:21 -04:00
|
|
|
op = ['~', '!', '@', '%']
|
2018-03-16 03:13:43 -04:00
|
|
|
|
|
|
|
@module.require_chanmsg
|
2019-10-08 11:45:21 -04:00
|
|
|
@module.require_admin
|
2018-03-16 03:13:43 -04:00
|
|
|
@module.commands('kick')
|
2020-01-08 07:51:00 -05:00
|
|
|
@module.example(".kick Rob It's time to stop.")
|
2018-03-16 03:13:43 -04:00
|
|
|
def kick(bot, trigger):
|
|
|
|
"""
|
|
|
|
Kick a user from the channel.
|
|
|
|
"""
|
2019-10-08 11:45:21 -04:00
|
|
|
if bot.channels[trigger.channel].users[bot.nick].op_level not in op:
|
2018-03-16 03:13:43 -04:00
|
|
|
return bot.reply("I'm not a channel operator!")
|
2020-01-07 18:58:19 -05:00
|
|
|
if len(trigger.args) < 2:
|
2018-03-16 03:13:43 -04:00
|
|
|
return bot.reply("Who do you want me to kick?")
|
2020-01-07 18:58:19 -05:00
|
|
|
target = trigger.args[1]
|
|
|
|
if len(trigger.args) >= 3:
|
|
|
|
reason = ' '.join(trigger.args[2:])
|
|
|
|
else:
|
2018-03-16 03:13:43 -04:00
|
|
|
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
|
2019-10-08 11:45:21 -04:00
|
|
|
@module.require_admin
|
2018-03-16 03:13:43 -04:00
|
|
|
@module.commands('ban')
|
2020-01-08 07:51:00 -05:00
|
|
|
@module.example(".ban Rob")
|
2018-03-16 03:13:43 -04:00
|
|
|
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.
|
|
|
|
"""
|
2019-10-08 11:45:21 -04:00
|
|
|
if bot.channels[trigger.channel].users[bot.nick].op_level not in op:
|
2018-03-16 03:13:43 -04:00
|
|
|
return bot.reply("I'm not a channel operator!")
|
2020-01-07 18:58:19 -05:00
|
|
|
if len(trigger.args) < 2:
|
2018-03-16 03:13:43 -04:00
|
|
|
return bot.reply("Who do you want me to ban?")
|
|
|
|
|
2020-01-07 18:58:19 -05:00
|
|
|
banmask = configureHostMask(trigger.args[1])
|
2018-03-16 03:13:43 -04:00
|
|
|
bot.mode(trigger.channel, True, "b", mask=banmask)
|
|
|
|
|
|
|
|
|
|
|
|
@module.require_chanmsg
|
2019-10-08 11:45:21 -04:00
|
|
|
@module.require_admin
|
2018-03-16 03:13:43 -04:00
|
|
|
@module.commands('unban')
|
2020-01-08 07:51:00 -05:00
|
|
|
@module.example(".unban Rob")
|
2018-03-16 03:13:43 -04:00
|
|
|
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.
|
|
|
|
"""
|
2019-10-08 11:45:21 -04:00
|
|
|
if bot.channels[trigger.channel].users[bot.nick].op_level not in op:
|
2018-03-16 03:13:43 -04:00
|
|
|
return bot.reply("I'm not a channel operator!")
|
2020-01-07 18:58:19 -05:00
|
|
|
if len(trigger.args) < 2:
|
2018-03-16 03:13:43 -04:00
|
|
|
return bot.reply("Who do you want me to ban?")
|
|
|
|
|
2020-01-07 18:58:19 -05:00
|
|
|
banmask = configureHostMask(trigger.args[1])
|
2018-03-16 03:13:43 -04:00
|
|
|
bot.mode(trigger.channel, False, "b", mask=banmask)
|
|
|
|
|
|
|
|
|
|
|
|
@module.require_chanmsg
|
2019-10-08 11:45:21 -04:00
|
|
|
@module.require_admin
|
2018-03-25 14:27:40 -04:00
|
|
|
@module.commands('kickban')
|
2020-01-08 07:51:00 -05:00
|
|
|
@module.example(".kickban Rob It's time to stop.")
|
2018-03-16 03:13:43 -04:00
|
|
|
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
|
|
|
|
"""
|
2019-10-08 11:45:21 -04:00
|
|
|
if bot.channels[trigger.channel].users[bot.nick].op_level not in op:
|
2018-03-16 03:13:43 -04:00
|
|
|
return bot.reply("I'm not a channel operator!")
|
2020-01-07 18:58:19 -05:00
|
|
|
if len(trigger.args) < 2:
|
2018-03-16 03:13:43 -04:00
|
|
|
return bot.reply("Who do you want me to ban?")
|
2020-01-07 18:58:19 -05:00
|
|
|
target = trigger.args[1]
|
|
|
|
if len(trigger.args) >= 3:
|
|
|
|
reason = ' '.join(trigger.args[2:])
|
|
|
|
else:
|
2018-03-16 03:13:43 -04:00
|
|
|
reason = "Stop doing the bad."
|
|
|
|
|
|
|
|
if target == bot.nick:
|
|
|
|
return bot.reply("I can't let you do that.")
|
|
|
|
|
2020-01-07 18:58:19 -05:00
|
|
|
banmask = configureHostMask(trigger.args[1])
|
2018-03-16 03:13:43 -04:00
|
|
|
bot.mode(trigger.channel, False, "b", mask=banmask)
|
|
|
|
bot.kick(trigger.channel, target, reason)
|
|
|
|
|
|
|
|
|
|
|
|
@module.require_chanmsg
|
2019-10-08 11:45:21 -04:00
|
|
|
@module.require_admin
|
2018-03-16 03:13:43 -04:00
|
|
|
@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.
|
|
|
|
"""
|
2019-10-08 11:45:21 -04:00
|
|
|
if bot.channels[trigger.channel].users[bot.nick].op_level not in op:
|
2018-03-16 03:13:43 -04:00
|
|
|
return bot.reply("I'm not a channel operator!")
|
2020-01-07 18:58:19 -05:00
|
|
|
if len(trigger.args) < 2:
|
2018-03-16 03:13:43 -04:00
|
|
|
return bot.reply("What do you want the topic set to?")
|
|
|
|
|
2020-01-07 18:58:19 -05:00
|
|
|
bot.topic(trigger.channel, ' '.join(trigger.args[1:]))
|