.banheall also more hacking in trigger.py

This commit is contained in:
iou1name 2018-01-19 18:55:18 -05:00
parent 808c46e1eb
commit 7f819740a8
5 changed files with 51 additions and 15 deletions

View File

@ -1,10 +1,6 @@
# coding=utf-8
# Copyright 2010-2011, Michael Yanovich, Alek Rollyson, and Elsie Powell
# Copyright © 2012, Elad Alfassa <elad@fedoraproject.org>
# 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

View File

@ -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")

View File

@ -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())

View File

@ -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')

View File

@ -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
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()