From 7f819740a816b53094a4c492f4d129e645d25f34 Mon Sep 17 00:00:00 2001 From: iou1name Date: Fri, 19 Jan 2018 18:55:18 -0500 Subject: [PATCH] .banheall also more hacking in trigger.py --- modules/adminchannel.py | 8 ++------ modules/banhe.py | 44 +++++++++++++++++++++++++++++++++++++---- modules/pingall.py | 5 ++--- modules/remind.py | 2 +- trigger.py | 7 ++++++- 5 files changed, 51 insertions(+), 15 deletions(-) diff --git a/modules/adminchannel.py b/modules/adminchannel.py index 25a2116..476b600 100755 --- a/modules/adminchannel.py +++ b/modules/adminchannel.py @@ -1,10 +1,6 @@ -# coding=utf-8 -# Copyright 2010-2011, Michael Yanovich, Alek Rollyson, and Elsie Powell -# Copyright © 2012, Elad Alfassa -# Licensed under the Eiffel Forum License 2. -from __future__ import unicode_literals, absolute_import, print_function, division - +#!/usr/bin/env python3 import re + import formatting from module import commands, priority, OP, HALFOP, require_privilege, require_chanmsg from tools import Identifier diff --git a/modules/banhe.py b/modules/banhe.py index f4428f6..4182af0 100755 --- a/modules/banhe.py +++ b/modules/banhe.py @@ -6,16 +6,17 @@ ban he """ import time -import module +from module import commands, example import modules.adminchannel -@module.commands('banhe') -@module.example('.banhe assfaggot 30m') +@commands('banhe') +@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. """ + print(trigger.group()) banhee, period = trigger.group(3), trigger.group(4) trigger.set_nick(bot.nick) @@ -37,5 +38,40 @@ def banhe(bot, trigger): bot.say(f"Banned \x0304{banhee}\x03 for \x0309{str(period)}\x03 seconds.") time.sleep(period) modules.adminchannel.unban(bot, trigger) - bot.say("Unbanned \x0304" + banhee + "\x03") + bot.say(f"Unbanned \x0304{banhee}\x03") + +@commands("banheall") +@example(".banheall") +def banheall(bot, trigger): + """ + Ban them all, Johnny. + """ + if not trigger.admin: + return + period = trigger.group(2) + trigger.set_nick(bot.nick) + + conv = {'s':1, 'm':60, 'h':3600, 'd':86400} + try: + period = conv[period[-1]] * int(period[:-1]) + except (KeyError, ValueError, TypeError): + period = 0 + + for nick in bot.privileges[trigger.sender].keys(): + trigger.set_group(f".banhe {nick}") + modules.adminchannel.ban(bot, trigger) + + if period > 2592000: + bot.reply("It's too big, Onii-chan.") + if not period or period > 2592000: + return bot.say("Banned \x0304them all\x03 for \x0309∞\x03 seconds.") + + bot.say(f"Banned \x0304them all\x03 for \x0309{str(period)}\x03 seconds.") + time.sleep(period) + + for nick in bot.privileges[trigger.sender].keys(): + trigger.set_group(f".banhe {nick}") + modules.adminchannel.unban(bot, trigger) + + bot.say("Unbanned \x0304them all\x03") diff --git a/modules/pingall.py b/modules/pingall.py index 1d9aea6..a443375 100755 --- a/modules/pingall.py +++ b/modules/pingall.py @@ -1,5 +1,4 @@ -#! /usr/bin/env python3 -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 """ Pings everyone in the channel. """ @@ -12,6 +11,6 @@ def pingAll(bot, trigger): attention, or just annoy them. """ msg = "" - for name, priv in bot.privileges[trigger.sender].items(): + for name in bot.privileges[trigger.sender].keys(): msg += name + ' ' bot.say(msg.strip()) diff --git a/modules/remind.py b/modules/remind.py index e5a6f14..3ff3de2 100755 --- a/modules/remind.py +++ b/modules/remind.py @@ -24,7 +24,7 @@ def filename(self): def load_database(name): data = {} if os.path.isfile(name): - f = codecs.open(name, 'r', encoding='utf-8') + f = codecs.open(name, 'r') for line in f: unixtime, channel, nick, message = line.split('\t') message = message.rstrip('\n') diff --git a/trigger.py b/trigger.py index 3a58d68..18e2ea9 100755 --- a/trigger.py +++ b/trigger.py @@ -186,4 +186,9 @@ class Trigger(str): def set_nick(self, new_nick): """Sets the trigger's nick to something new.""" self._pretrigger.nick = new_nick - self._nick = self._pretrigger.nick \ No newline at end of file + self._nick = self._pretrigger.nick + + def set_group(self, new_group): + """Sets the trigger's group to something new.""" + self._match = re.match("\..+", new_group) + self._group = self._match.group()