Commit f8294adb authored by Benjamin Graillot's avatar Benjamin Graillot

Fix del et listall

parent c4dd172f
......@@ -9,10 +9,20 @@ from bot import Bot
import config
from subs import subs
def write_subs(subs):
with open('subs', 'w') as s:
with open('subs.py', 'w') as s:
s.write('subs={' + ','.join([repr(source)+':{' + ','.join([repr(nick) + ':{' + ','.join([repr(channel) + ':[' + ','.join([repr(patt) for patt in subs[source][nick][channel]]) + ']' for channel in subs[source][nick]]) + '}' for nick in subs[source]]) + '}' for source in subs]) + ' }\n')
def subscribed(channel):
global subs
for source in subs:
for nick in subs[source]:
if channel in subs[source][nick]:
return True
return False
class Ninja(Bot):
def __init__(self):
Bot.__init__(self, "NinjaBot")
......@@ -139,8 +149,8 @@ class Ninja(Bot):
conn.privmsg(nick, "Vous n'avez pas d'abonnement à {source} sur {channel}".format(source=command[1], channel=channel))
return
elif len(command) == 3:
if channel in subs[nick][source]:
del subs[nick][source][channel]
if channel in subs[source][nick]:
del subs[source][nick][channel]
conn.privmsg(nick, "Vos abonnements à {source} sur {channel} on été supprimés".format(source=command[1], channel=channel))
if channel[0] in config.channel_start:
if not subscribed(channel):
......@@ -148,12 +158,12 @@ class Ninja(Bot):
elif len(command) == 4:
if command[3].isnumeric():
n = int(command[3])
if n < len(subs[source][channel]):
subscription = subs[source][channel][n]
del subs[source][channel][n]
if n < len(subs[source][nick][channel]):
subscription = subs[source][nick][channel][n]
del subs[source][nick][channel][n]
conn.privmsg(nick, "Votre abonnement, {subscription}, à {source} sur {channel} a été supprimé".format(subscription=subscription, source=command[1], channel=channel))
if len(subs[source][channel]) == 0:
del subs[source][channel]
if len(subs[source][nick][channel]) == 0:
del subs[source][nick][channel]
if channel[0] in config.channel_start:
if not subscribed(channel):
conn.part(channel, "Plus d'abonnement sur {channel}".format(channel=channel))
......@@ -184,6 +194,7 @@ class Ninja(Bot):
self.do_command_ext(conn, command[2:], 0, command[1])
elif command[0].casefold() == "listall" and level >= 100:
for source in subs:
conn.privmsg(nick, source + ':')
for n in subs[source]:
conn.privmsg(nick, ' - ' + n + ':')
for channel in subs[source][n]:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment