banhe is more robust. i think.
This commit is contained in:
parent
ce7e3fdddb
commit
446b53db61
20
bot.py
20
bot.py
|
@ -249,6 +249,26 @@ class Sopel(irc.Bot):
|
||||||
else:
|
else:
|
||||||
self.write(['JOIN', channel, password])
|
self.write(['JOIN', channel, password])
|
||||||
|
|
||||||
|
def ban(self, banmask, channel):
|
||||||
|
"""
|
||||||
|
Attempts to ban the recipient.
|
||||||
|
"""
|
||||||
|
banmask = Identifier(banmask)
|
||||||
|
banmask = tools.configureHostMask(banmask)
|
||||||
|
if banmask == "":
|
||||||
|
return
|
||||||
|
self.write(['MODE', channel, '+b', banmask])
|
||||||
|
|
||||||
|
def unban(self, banmask, channel):
|
||||||
|
"""
|
||||||
|
Attempts to unban the recipient.
|
||||||
|
"""
|
||||||
|
banmask = Identifier(banmask)
|
||||||
|
banmask = tools.configureHostMask(banmask)
|
||||||
|
if banmask == "":
|
||||||
|
return
|
||||||
|
self.write(['MODE', channel, '-b', banmask])
|
||||||
|
|
||||||
def say(self, text, recipient, max_messages=1):
|
def say(self, text, recipient, max_messages=1):
|
||||||
"""Send ``text`` as a PRIVMSG to ``recipient``.
|
"""Send ``text`` as a PRIVMSG to ``recipient``.
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import re
|
||||||
|
|
||||||
import formatting
|
import formatting
|
||||||
from module import commands, priority, OP, HALFOP, require_privilege, require_chanmsg, example
|
from module import commands, priority, OP, HALFOP, require_privilege, require_chanmsg, example
|
||||||
from tools import Identifier
|
from tools import Identifier, configureHostMask
|
||||||
|
|
||||||
|
|
||||||
def default_mask(trigger):
|
def default_mask(trigger):
|
||||||
|
@ -44,28 +44,6 @@ def kick(bot, trigger):
|
||||||
bot.write(['KICK', channel, nick], reason)
|
bot.write(['KICK', channel, nick], reason)
|
||||||
|
|
||||||
|
|
||||||
def configureHostMask(mask):
|
|
||||||
if mask == '*!*@*':
|
|
||||||
return mask
|
|
||||||
if re.match('^[^.@!/]+$', mask) is not None:
|
|
||||||
return '%s!*@*' % mask
|
|
||||||
if re.match('^[^@!]+$', mask) is not None:
|
|
||||||
return '*!*@%s' % mask
|
|
||||||
|
|
||||||
m = re.match('^([^!@]+)@$', mask)
|
|
||||||
if m is not None:
|
|
||||||
return '*!%s@*' % m.group(1)
|
|
||||||
|
|
||||||
m = re.match('^([^!@]+)@([^@!]+)$', mask)
|
|
||||||
if m is not None:
|
|
||||||
return '*!%s@%s' % (m.group(1), m.group(2))
|
|
||||||
|
|
||||||
m = re.match('^([^!@]+)!(^[!@]+)@?$', mask)
|
|
||||||
if m is not None:
|
|
||||||
return '%s!%s@*' % (m.group(1), m.group(2))
|
|
||||||
return ''
|
|
||||||
|
|
||||||
|
|
||||||
@require_chanmsg
|
@require_chanmsg
|
||||||
@require_privilege(OP, 'You are not a channel operator.')
|
@require_privilege(OP, 'You are not a channel operator.')
|
||||||
@commands('ban')
|
@commands('ban')
|
||||||
|
@ -90,11 +68,7 @@ def ban(bot, trigger):
|
||||||
return
|
return
|
||||||
channel = opt
|
channel = opt
|
||||||
banmask = text[2]
|
banmask = text[2]
|
||||||
banmask = configureHostMask(banmask)
|
bot.ban(banmask, channel)
|
||||||
if banmask == '':
|
|
||||||
return
|
|
||||||
bot.write(['MODE', channel, '+b', banmask])
|
|
||||||
|
|
||||||
|
|
||||||
@require_chanmsg
|
@require_chanmsg
|
||||||
@require_privilege(OP, 'You are not a channel operator.')
|
@require_privilege(OP, 'You are not a channel operator.')
|
||||||
|
@ -118,11 +92,7 @@ def unban(bot, trigger):
|
||||||
return
|
return
|
||||||
channel = opt
|
channel = opt
|
||||||
banmask = text[2]
|
banmask = text[2]
|
||||||
banmask = configureHostMask(banmask)
|
bot.unban(banmask, channel)
|
||||||
if banmask == '':
|
|
||||||
return
|
|
||||||
bot.write(['MODE', channel, '-b', banmask])
|
|
||||||
|
|
||||||
|
|
||||||
@require_chanmsg
|
@require_chanmsg
|
||||||
@require_privilege(OP, 'You are not a channel operator.')
|
@require_privilege(OP, 'You are not a channel operator.')
|
||||||
|
@ -153,10 +123,7 @@ def kickban(bot, trigger):
|
||||||
mask = text[3]
|
mask = text[3]
|
||||||
reasonidx = 4
|
reasonidx = 4
|
||||||
reason = ' '.join(text[reasonidx:])
|
reason = ' '.join(text[reasonidx:])
|
||||||
mask = configureHostMask(mask)
|
bot.ban(mask, channel)
|
||||||
if mask == '':
|
|
||||||
return
|
|
||||||
bot.write(['MODE', channel, '+b', mask])
|
|
||||||
bot.write(['KICK', channel, nick], reason)
|
bot.write(['KICK', channel, nick], reason)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ def banhe(bot, trigger):
|
||||||
"""
|
"""
|
||||||
print(trigger.group())
|
print(trigger.group())
|
||||||
banhee, period = trigger.group(3), trigger.group(4)
|
banhee, period = trigger.group(3), trigger.group(4)
|
||||||
trigger.set_nick(bot.nick)
|
|
||||||
|
|
||||||
if not trigger.admin:
|
if not trigger.admin:
|
||||||
period = 20
|
period = 20
|
||||||
|
@ -29,7 +28,7 @@ def banhe(bot, trigger):
|
||||||
except (KeyError, ValueError, TypeError):
|
except (KeyError, ValueError, TypeError):
|
||||||
period = 0
|
period = 0
|
||||||
|
|
||||||
modules.adminchannel.ban(bot, trigger)
|
bot.ban(banhee, trigger.sender)
|
||||||
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:
|
||||||
|
@ -37,29 +36,32 @@ def banhe(bot, trigger):
|
||||||
|
|
||||||
bot.say(f"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, trigger)
|
bot.unban(banhee, trigger.sender)
|
||||||
bot.say(f"Unbanned \x0304{banhee}\x03")
|
bot.say(f"Unbanned \x0304{banhee}\x03")
|
||||||
|
|
||||||
|
|
||||||
@require_admin
|
@require_admin
|
||||||
@commands("banheall")
|
@commands("banheall")
|
||||||
def banheall(bot, trigger):
|
def banheallCommand(bot, trigger):
|
||||||
"""
|
"""
|
||||||
Ban them all, Johnny.
|
Ban them all, Johnny.
|
||||||
"""
|
"""
|
||||||
period = trigger.group(2)
|
period = trigger.group(2)
|
||||||
print(bot.nick)
|
banheall(bot, period, trigger.sender)
|
||||||
trigger.set_nick(bot.nick)
|
|
||||||
|
|
||||||
|
|
||||||
|
def banheall(bot, period, channel):
|
||||||
|
"""
|
||||||
|
The real banhe.
|
||||||
|
"""
|
||||||
conv = {'s':1, 'm':60, 'h':3600, 'd':86400}
|
conv = {'s':1, 'm':60, 'h':3600, 'd':86400}
|
||||||
try:
|
try:
|
||||||
period = conv[period[-1]] * int(period[:-1])
|
period = conv[period[-1]] * int(period[:-1])
|
||||||
except (KeyError, ValueError, TypeError):
|
except (KeyError, ValueError, TypeError):
|
||||||
period = 0
|
period = 0
|
||||||
|
|
||||||
for nick in bot.privileges[trigger.sender].keys():
|
for nick in bot.privileges[channel].keys():
|
||||||
trigger.set_group(f".banhe {nick}")
|
bot.ban(nick, channel)
|
||||||
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.")
|
||||||
|
@ -69,8 +71,7 @@ def banheall(bot, trigger):
|
||||||
bot.say(f"Banned \x0304them all\x03 for \x0309{str(period)}\x03 seconds.")
|
bot.say(f"Banned \x0304them all\x03 for \x0309{str(period)}\x03 seconds.")
|
||||||
time.sleep(period)
|
time.sleep(period)
|
||||||
|
|
||||||
for nick in bot.privileges[trigger.sender].keys():
|
for nick in bot.privileges[channel].keys():
|
||||||
trigger.set_group(f".banhe {nick}")
|
bot.unban(nick, channel)
|
||||||
modules.adminchannel.unban(bot, trigger)
|
|
||||||
|
|
||||||
bot.say("Unbanned \x0304them all\x03")
|
bot.say("Unbanned \x0304them all\x03")
|
||||||
|
|
|
@ -331,3 +331,28 @@ class SopelMemoryWithDefault(defaultdict):
|
||||||
def contains(self, key):
|
def contains(self, key):
|
||||||
"""Backwards compatability with 3.x, use `in` operator instead."""
|
"""Backwards compatability with 3.x, use `in` operator instead."""
|
||||||
return self.__contains__(key)
|
return self.__contains__(key)
|
||||||
|
|
||||||
|
def configureHostMask(mask):
|
||||||
|
"""
|
||||||
|
Returns a valid hostmask based on user input.
|
||||||
|
"""
|
||||||
|
if mask == '*!*@*':
|
||||||
|
return mask
|
||||||
|
if re.match('^[^.@!/]+$', mask) is not None:
|
||||||
|
return '%s!*@*' % mask
|
||||||
|
if re.match('^[^@!]+$', mask) is not None:
|
||||||
|
return '*!*@%s' % mask
|
||||||
|
|
||||||
|
m = re.match('^([^!@]+)@$', mask)
|
||||||
|
if m is not None:
|
||||||
|
return '*!%s@*' % m.group(1)
|
||||||
|
|
||||||
|
m = re.match('^([^!@]+)@([^@!]+)$', mask)
|
||||||
|
if m is not None:
|
||||||
|
return '*!%s@%s' % (m.group(1), m.group(2))
|
||||||
|
|
||||||
|
m = re.match('^([^!@]+)!(^[!@]+)@?$', mask)
|
||||||
|
if m is not None:
|
||||||
|
return '%s!%s@*' % (m.group(1), m.group(2))
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user