fulvia/modules/banhe.py

75 lines
2.0 KiB
Python
Raw Normal View History

2018-03-16 03:13:43 -04:00
#!/usr/bin/env python3
"""
ban he
ban he
ban he
"""
import time
from module import commands, example, require_admin
from tools import configureHostMask
@commands('banhe')
2020-01-08 07:51:00 -05:00
@example('.banhe Rob 30m')
2018-03-16 03:13:43 -04:00
def banhe(bot, trigger):
"""
Bans he for a set period of time. Admins may set the period of time,
non-admins only get 20 second bans.
"""
2020-01-07 18:58:19 -05:00
banhee = trigger.args[1] if len(trigger.args) >= 2 else ''
period = trigger.args[2] if len(trigger.args) >= 3 else ''
2018-03-16 03:13:43 -04:00
if not trigger.admin:
period = 20
else:
conv = {'s':1, 'm':60, 'h':3600, 'd':86400}
try:
period = conv[period[-1]] * int(period[:-1])
2020-01-07 18:58:19 -05:00
except (KeyError, ValueError, TypeError, IndexError):
2018-03-16 03:13:43 -04:00
period = 0
banmask = configureHostMask(banhee)
bot.mode(trigger.channel, True, "b", mask=banmask)
if period > 2592000:
2020-01-08 07:51:00 -05:00
bot.reply("Onii-chan, It's too big!")
2018-03-16 03:13:43 -04:00
if not period or period > 2592000:
2018-05-25 15:21:18 -04:00
return bot.msg(f"Banned \x0304{banhee}\x03 for \x0309∞\x03 seconds.")
2018-03-16 03:13:43 -04:00
2018-05-25 15:21:18 -04:00
bot.msg(f"Banned \x0304{banhee}\x03 for \x0309{str(period)}\x03 seconds.")
2018-03-16 03:13:43 -04:00
time.sleep(period)
bot.mode(trigger.channel, False, "b", mask=banmask)
2018-05-25 15:21:18 -04:00
bot.msg(f"Unbanned \x0304{banhee}\x03")
2018-03-16 03:13:43 -04:00
@require_admin
@commands("banheall")
def banheall(bot, trigger):
"""
Ban them all, Johnny.
"""
2020-01-07 18:58:19 -05:00
period = trigger.args[1] if len(trigger.args) >= 2 else '20s'
2018-03-16 03:13:43 -04:00
conv = {'s':1, 'm':60, 'h':3600, 'd':86400}
try:
period = conv[period[-1]] * int(period[:-1])
except (IndexError, KeyError, ValueError, TypeError):
period = 0
for nick in bot.channels[trigger.channel].users.keys():
2018-03-16 03:13:43 -04:00
banmask = configureHostMask(nick)
bot.mode(trigger.channel, True, "b", mask=banmask)
if period > 2592000:
2020-01-08 07:51:00 -05:00
bot.reply("Onii-chan, It's too big!")
2018-03-16 03:13:43 -04:00
if not period or period > 2592000:
2018-05-25 15:21:18 -04:00
return bot.msg("Banned \x0304them all\x03 for \x0309∞\x03 seconds.")
2018-03-16 03:13:43 -04:00
2018-05-25 15:21:18 -04:00
bot.msg(f"Banned \x0304them all\x03 for \x0309{str(period)}\x03 seconds.")
2018-03-16 03:13:43 -04:00
time.sleep(period)
for nick in bot.channels[trigger.channel].users.keys():
2018-03-16 03:13:43 -04:00
banmask = configureHostMask(nick)
bot.mode(trigger.channel, False, "b", mask=banmask)
2018-05-25 15:21:18 -04:00
bot.msg("Unbanned \x0304them all\x03")