made it so you can set trigger.nick to something new

This commit is contained in:
iou1name 2018-01-19 18:04:38 -05:00
parent 5b1909cac5
commit 808c46e1eb
3 changed files with 25 additions and 41 deletions

View File

@ -1,15 +1,13 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
"""
ban he
ban he
ban he
"""
import time
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')
@ -19,14 +17,7 @@ def banhe(bot, trigger):
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)
trigger.set_nick(bot.nick)
if not trigger.admin:
period = 20
@ -37,13 +28,14 @@ def banhe(bot, trigger):
except (KeyError, ValueError, TypeError):
period = 0
modules.adminchannel.ban(bot, fake_trigger)
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 \x0304" + banhee + "\x03 for \x0309∞\x03 seconds.")
return bot.say(f"Banned \x0304{banhee}\x03 for \x0309∞\x03 seconds.")
bot.say("Banned \x0304" + banhee + "\x03 for \x0309" + str(period) + "\x03 seconds.")
bot.say(f"Banned \x0304{banhee}\x03 for \x0309{str(period)}\x03 seconds.")
time.sleep(period)
modules.adminchannel.unban(bot, fake_trigger)
modules.adminchannel.unban(bot, trigger)
bot.say("Unbanned \x0304" + banhee + "\x03")

View File

@ -1,31 +1,21 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
"""
remind.py - Sopel Reminder Module
Copyright 2011, Sean B. Palmer, inamidst.com
Licensed under the Eiffel Forum License 2.
http://sopel.chat
Reminds of things.
"""
from __future__ import unicode_literals, absolute_import, print_function, division
import os
import re
import time
import threading
import collections
import codecs
import pytz
from datetime import datetime
from module import commands, example, NOLIMIT
import tools
from tools.time import get_timezone, format_time
try:
import pytz
except:
pytz = None
def filename(self):
name = self.nick + '-' + self.config.core.host + '.reminders.db'
return os.path.join(self.config.core.homedir, name)

View File

@ -1,16 +1,13 @@
# coding=utf-8
from __future__ import unicode_literals, absolute_import, print_function, division
#!/usr/bin/env python3
"""
The trigger abstraction layer.
"""
import re
import sys
import datetime
import tools
if sys.version_info.major >= 3:
unicode = str
basestring = str
class PreTrigger(object):
"""A parsed message from the server, which has not been matched against
@ -90,7 +87,7 @@ class PreTrigger(object):
self.tags['account'] = self.args[1]
class Trigger(unicode):
class Trigger(str):
"""A line from the server, which has matched a callable's rules.
Note that CTCP messages (`PRIVMSG`es and `NOTICE`es which start and end
@ -161,7 +158,7 @@ class Trigger(unicode):
"""
def __new__(cls, config, message, match, account=None):
self = unicode.__new__(cls, message.args[-1] if message.args else '')
self = str.__new__(cls, message.args[-1] if message.args else '')
self._account = account
self._pretrigger = message
self._match = match
@ -185,3 +182,8 @@ class Trigger(unicode):
)
return self
def set_nick(self, new_nick):
"""Sets the trigger's nick to something new."""
self._pretrigger.nick = new_nick
self._nick = self._pretrigger.nick