made it so you can set trigger.nick to something new
This commit is contained in:
parent
5b1909cac5
commit
808c46e1eb
|
@ -1,15 +1,13 @@
|
||||||
#! /usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
ban he
|
ban he
|
||||||
ban he
|
ban he
|
||||||
ban he
|
ban he
|
||||||
"""
|
"""
|
||||||
|
import time
|
||||||
|
|
||||||
import module
|
import module
|
||||||
import modules.adminchannel
|
import modules.adminchannel
|
||||||
import time
|
|
||||||
from trigger import PreTrigger, Trigger
|
|
||||||
from tools import Identifier, get_command_regexp
|
|
||||||
|
|
||||||
@module.commands('banhe')
|
@module.commands('banhe')
|
||||||
@module.example('.banhe assfaggot 30m')
|
@module.example('.banhe assfaggot 30m')
|
||||||
|
@ -19,14 +17,7 @@ def banhe(bot, trigger):
|
||||||
non-admins only get 20 second bans.
|
non-admins only get 20 second bans.
|
||||||
"""
|
"""
|
||||||
banhee, period = trigger.group(3), trigger.group(4)
|
banhee, period = trigger.group(3), trigger.group(4)
|
||||||
|
trigger.set_nick(bot.nick)
|
||||||
# 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:
|
if not trigger.admin:
|
||||||
period = 20
|
period = 20
|
||||||
|
@ -37,13 +28,14 @@ def banhe(bot, trigger):
|
||||||
except (KeyError, ValueError, TypeError):
|
except (KeyError, ValueError, TypeError):
|
||||||
period = 0
|
period = 0
|
||||||
|
|
||||||
modules.adminchannel.ban(bot, fake_trigger)
|
modules.adminchannel.ban(bot, trigger)
|
||||||
if period > 2592000:
|
if period > 2592000:
|
||||||
bot.reply("It's too big, Onii-chan.")
|
bot.reply("It's too big, Onii-chan.")
|
||||||
if not period or period > 2592000:
|
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)
|
time.sleep(period)
|
||||||
modules.adminchannel.unban(bot, fake_trigger)
|
modules.adminchannel.unban(bot, trigger)
|
||||||
bot.say("Unbanned \x0304" + banhee + "\x03")
|
bot.say("Unbanned \x0304" + banhee + "\x03")
|
||||||
|
|
||||||
|
|
|
@ -1,31 +1,21 @@
|
||||||
#! /usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
remind.py - Sopel Reminder Module
|
Reminds of things.
|
||||||
Copyright 2011, Sean B. Palmer, inamidst.com
|
|
||||||
Licensed under the Eiffel Forum License 2.
|
|
||||||
|
|
||||||
http://sopel.chat
|
|
||||||
"""
|
"""
|
||||||
from __future__ import unicode_literals, absolute_import, print_function, division
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
import collections
|
import collections
|
||||||
import codecs
|
import codecs
|
||||||
|
|
||||||
|
import pytz
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from module import commands, example, NOLIMIT
|
from module import commands, example, NOLIMIT
|
||||||
import tools
|
import tools
|
||||||
from tools.time import get_timezone, format_time
|
from tools.time import get_timezone, format_time
|
||||||
|
|
||||||
try:
|
|
||||||
import pytz
|
|
||||||
except:
|
|
||||||
pytz = None
|
|
||||||
|
|
||||||
|
|
||||||
def filename(self):
|
def filename(self):
|
||||||
name = self.nick + '-' + self.config.core.host + '.reminders.db'
|
name = self.nick + '-' + self.config.core.host + '.reminders.db'
|
||||||
return os.path.join(self.config.core.homedir, name)
|
return os.path.join(self.config.core.homedir, name)
|
||||||
|
|
20
trigger.py
20
trigger.py
|
@ -1,16 +1,13 @@
|
||||||
# coding=utf-8
|
#!/usr/bin/env python3
|
||||||
from __future__ import unicode_literals, absolute_import, print_function, division
|
"""
|
||||||
|
The trigger abstraction layer.
|
||||||
|
"""
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
import tools
|
import tools
|
||||||
|
|
||||||
if sys.version_info.major >= 3:
|
|
||||||
unicode = str
|
|
||||||
basestring = str
|
|
||||||
|
|
||||||
|
|
||||||
class PreTrigger(object):
|
class PreTrigger(object):
|
||||||
"""A parsed message from the server, which has not been matched against
|
"""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]
|
self.tags['account'] = self.args[1]
|
||||||
|
|
||||||
|
|
||||||
class Trigger(unicode):
|
class Trigger(str):
|
||||||
"""A line from the server, which has matched a callable's rules.
|
"""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
|
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):
|
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._account = account
|
||||||
self._pretrigger = message
|
self._pretrigger = message
|
||||||
self._match = match
|
self._match = match
|
||||||
|
@ -185,3 +182,8 @@ class Trigger(unicode):
|
||||||
)
|
)
|
||||||
|
|
||||||
return self
|
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
|
Loading…
Reference in New Issue
Block a user