50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
|
#! /usr/bin/env python3
|
||
|
# -*- coding: utf-8 -*-
|
||
|
"""
|
||
|
ban he
|
||
|
ban he
|
||
|
ban he
|
||
|
"""
|
||
|
import module
|
||
|
import modules.adminchannel
|
||
|
import time
|
||
|
from trigger import PreTrigger, Trigger
|
||
|
from tools import Identifier, get_command_regexp
|
||
|
|
||
|
@module.commands('banhe')
|
||
|
@module.example('.banhe assfaggot 30m')
|
||
|
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.
|
||
|
"""
|
||
|
banhee, period = trigger.group(3), trigger.group(4)
|
||
|
|
||
|
# here we construct a brand new trigger from scratch becasue doing
|
||
|
# things the right way just isn't in the budget.
|
||
|
fake_line = ":" + bot.nick + trigger.raw[trigger.raw.find("!"):]
|
||
|
fake_pretrigger = PreTrigger(trigger.nick, fake_line)
|
||
|
fake_regexp = get_command_regexp(".", "banhe")
|
||
|
fake_match = fake_regexp.match(fake_pretrigger.args[-1])
|
||
|
fake_trigger = Trigger(bot.config, fake_pretrigger, fake_match)
|
||
|
|
||
|
if not trigger.admin:
|
||
|
period = 20
|
||
|
else:
|
||
|
conv = {'s':1, 'm':60, 'h':3600, 'd':86400}
|
||
|
try:
|
||
|
period = conv[period[-1]] * int(period[:-1])
|
||
|
except (KeyError, ValueError, TypeError):
|
||
|
period = 0
|
||
|
|
||
|
modules.adminchannel.ban(bot, fake_trigger)
|
||
|
if period > 2592000:
|
||
|
bot.reply("It's too big, Onii-chan.")
|
||
|
if not period or period > 2592000:
|
||
|
return bot.say("Banned \x0304" + banhee + "\x03 for \x0309∞\x03 seconds.")
|
||
|
|
||
|
bot.say("Banned \x0304" + banhee + "\x03 for \x0309" + str(period) + "\x03 seconds.")
|
||
|
time.sleep(period)
|
||
|
modules.adminchannel.unban(bot, fake_trigger)
|
||
|
bot.say("Unbanned \x0304" + banhee + "\x03")
|