fulvia/modules/adalwulf__.py

53 lines
1.5 KiB
Python
Raw Normal View History

2019-10-07 16:37:39 -04:00
#!/usr/bin/env python3
"""
Renames defaultnick's to Adalwulf__.
"""
from module import user_joined, commands, require_owner
MAX_NICKLEN = 100
NICK_ZERO = 'Adalwulf_'
def new_bot_name(number):
"""
Accepts the number of the new bot. Returns the nickname.
"""
max_underscore = MAX_NICKLEN - len(NICK_ZERO)
pluses = 0
while number > max_underscore * 2:
pluses += 1
number -= max_underscore * 2 + 1
max_underscore -= 1
equals = max(number - max_underscore, 0)
under = min(number, max_underscore) - equals
nick = NICK_ZERO + '+' * pluses + '|' * equals + '_' * under
return nick
@user_joined(True)
def adalwulf_(bot, trigger):
"""Renames adalwulf__."""
if not trigger.nick.startswith('defaultnick'):
return
names = bot.channels[trigger.channel].users
adals = [nick for nick in names if nick.startswith('Adalwulf__')]
adals += [nick for nick in names if nick.startswith('Adalwulf_|')]
old_nick = trigger.nick
new_nick = new_bot_name(len(adals) + 1)
bot.sendLine(f"SANICK {old_nick} {new_nick}")
@require_owner
@commands('rename_hydra')
def rename_hydra(bot, trigger):
"""Renames defaultnick's appropriately."""
for nick in list(bot.channels[trigger.channel].users.keys()):
if not nick.startswith('defaultnick'):
continue
names = bot.channels[trigger.channel].users
adals = [nick for nick in names if nick.startswith('Adalwulf__')]
adals += [nick for nick in names if nick.startswith('Adalwulf_|')]
old_nick = nick
new_nick = new_bot_name(len(adals) + 1)
print(f"SANICK {old_nick} {new_nick}")
bot.sendLine(f"SANICK {old_nick} {new_nick}")