Commit 08e4ec67 authored by Mindiell's avatar Mindiell

Fixing bugs

parent 2868f4d0
...@@ -6,8 +6,8 @@ INSERT INTO moderator VALUES ('Mindiell'); ...@@ -6,8 +6,8 @@ INSERT INTO moderator VALUES ('Mindiell');
CREATE TABLE tweets (last_entry_published varchar(40)); CREATE TABLE tweets (last_entry_published varchar(40));
INSERT INTO tweets VALUES ('2015-01-01 00:00:00 UTC'); INSERT INTO tweets VALUES ('2015-01-01 00:00:00 UTC');
CREATE TABLE wiki (last_entry_published varchar(40)); CREATE TABLE wikis (last_entry_updated varchar(40));
INSERT INTO wiki VALUES ('2015-01-01 00:00:00 UTC'); INSERT INTO wikis VALUES ('2015-01-01 00:00:00 UTC');
CREATE TABLE rpator (name varchar(50), score int); CREATE TABLE rpator (name varchar(50), score int);
...@@ -30,6 +30,8 @@ LOG_LEVEL = DEBUG ...@@ -30,6 +30,8 @@ LOG_LEVEL = DEBUG
MASTER_SCORE = 5 MASTER_SCORE = 5
MASTER_CLEANING = 7 # in days MASTER_CLEANING = 7 # in days
RP_CHANNEL = "#mytipy"
animals = [ animals = [
{ {
"left": """><((('>""", "left": """><((('>""",
...@@ -193,8 +195,8 @@ class Wantzel(object): ...@@ -193,8 +195,8 @@ class Wantzel(object):
next_week.tm_mday, next_week.tm_mday,
time.tzname[0] time.tzname[0]
), "%Y-%m-%d %Z") ), "%Y-%m-%d %Z")
# Sequence for op_mode verification # Sequence for op_mode verification (fibonacci)
self.op_sequence = [2, 3, 5, 8, 13, 21, 34, 55] self.op_sequence = [1, 2, 3, 5, 8, 13, 21, 34, 55]
self.op_offset = 0 self.op_offset = 0
self.op_counter = 0 self.op_counter = 0
# Number of articles actually waiting # Number of articles actually waiting
...@@ -242,7 +244,7 @@ class Wantzel(object): ...@@ -242,7 +244,7 @@ class Wantzel(object):
# Tell on channel if wiki was modified since last time # Tell on channel if wiki was modified since last time
self.wiki_updates() self.wiki_updates()
# Cleaning points of mastering rp # Cleaning points of mastering rp
if time.localtime()>next_cleaning: if time.localtime()>self.next_cleaning:
self.clean_master_rp() self.clean_master_rp()
# Recalling the timer # Recalling the timer
reactor.callLater(config.timer, self.timer) reactor.callLater(config.timer, self.timer)
...@@ -269,7 +271,8 @@ class Wantzel(object): ...@@ -269,7 +271,8 @@ class Wantzel(object):
if flag_set: if flag_set:
# thanks to user # thanks to user
self.send_message(channel, messages["oped"] % user) self.send_message(channel, messages["oped"] % user)
# reset sequence # reset counter and sequence
self.op_counter = 0
self.op_offset = 0 self.op_offset = 0
else: else:
# bad user ;o( # bad user ;o(
...@@ -280,32 +283,23 @@ class Wantzel(object): ...@@ -280,32 +283,23 @@ class Wantzel(object):
Verify if wantzel is chan operator, if not it complains on the chan <3. Verify if wantzel is chan operator, if not it complains on the chan <3.
""" """
Utils.debug("op_verification method") Utils.debug("op_verification method")
# Testing based on fibonacci sequence # Bot tries to list channel users, if it can't, then it is no more an op
self.op_counter += 1 self.irc.client.sendLine("NAMES %s" % RP_CHANNEL)
Utils.debug("op_counter : %s" % op_counter)
Utils.debug("op_offset : %s" % self.op_offset)
Utils.debug("op_sequence : %s" % self.op_sequence[self.op_offset])
if self.op_counter>self.op_sequence[self.op_offset]:
# Bot tries to list channel users, if it can't, then it is no more an op
self.irc.client.sendLine("NAMES #lqdn-rp")
def irc_unknown(self, prefix, command, params): def irc_unknown(self, prefix, command, params):
""" """
This Callback is called whenever the bot tries to perform the command "NAMES" on the This Callback is called whenever the bot tries to perform the command "NAMES" on the
#lqdn-rp channel. If it occurs, then the bot knows that it is no more op and beg for RP_CHANNEL channel. If it occurs, then the bot knows that it is no more op and beg for
a mode change to actual operators on the channel. a mode change to actual operators on the channel.
""" """
Utils.debug("UNKNOWN %s %s %s" % (prefix, command, params)) Utils.debug("UNKNOWN %s %s %s" % (prefix, command, params))
if command=="RPL_NAMREPLY": if command=="RPL_NAMREPLY":
# Beg for operator mode # Beg for operator mode
self.names(params) self.names(params)
# Then move the sequence further in order not to spam channel
if self.op_offset<len(self.op_sequence):
self.op_offset += 1
def names(self, params): def names(self, params):
""" """
Send a message on channel #lqdn-rp to beg an op mode to each actual operators. Send a message on channel RP_CHANNEL to beg an op mode to each actual operators.
params is an array with : params is an array with :
- params[0]: - params[0]:
- params[1]: - params[1]:
...@@ -313,10 +307,21 @@ class Wantzel(object): ...@@ -313,10 +307,21 @@ class Wantzel(object):
- params[3]: the list of all users on the channel - params[3]: the list of all users on the channel
""" """
Utils.debug("Names : %s" % params) Utils.debug("Names : %s" % params)
if params[2]=="#lqdn-rp": if params[2]==RP_CHANNEL:
ops = [user[1:] for user in params[3].split() if user[0]=="@"] ops = [user[1:] for user in params[3].split() if user[0]=="@"]
if "@"+self.irc.client.nickname not in params[3]: if "@"+self.irc.client.nickname not in params[3]:
self.send_message(params[2], messages["please_op"] % ", ".join(ops)) # Testing based on fibonacci sequence
self.op_counter += 1
Utils.debug("op_counter : %s" % self.op_counter)
Utils.debug("op_offset : %s" % self.op_offset)
Utils.debug("op_sequence : %s" % self.op_sequence[self.op_offset])
if self.op_counter>self.op_sequence[self.op_offset]:
self.send_message(params[2], messages["please_op"] % ", ".join(ops))
# Then reset op_counter
self.op_counter = 0
# And move the sequence further in order not to spam channel
if self.op_offset<len(self.op_sequence)-1:
self.op_offset += 1
def send_message(self, channel, multiline_message): def send_message(self, channel, multiline_message):
""" """
...@@ -497,24 +502,24 @@ class Wantzel(object): ...@@ -497,24 +502,24 @@ class Wantzel(object):
# Retrieve user's score in database # Retrieve user's score in database
connection = sqlite3.connect(config.sqlite_db) connection = sqlite3.connect(config.sqlite_db)
score = 0 score = 0
for row in connection.execute("SELECT score FROM rpator WHERE user='%s'" % user): for row in connection.execute("SELECT score FROM rpator WHERE name='%s'" % user):
known_user = True known_user = True
score = int(row[0]) score = int(row[0])
if score>MASTER_SCORE: if score>MASTER_SCORE:
master_user = True master_user = True
# Store new score for this user # Channel is RP_CHANNEL, so the user is knowing the rp yet
if known_user: if channel==RP_CHANNEL:
connection.execute("UPDATE rpator SET score=score+1 WHERE user='%s'" % user)
else:
connection.execute("INSERT INTO rpator (name, score) VALUES ('%s', 1)" % user)
# Channel is #lqdn-rp, so the user is knowing the rp yet
if channel=="#lqdn-rp":
know_rp = True know_rp = True
Utils.debug("know_rp : %s" % know_rp) Utils.debug("know_rp : %s" % know_rp)
Utils.debug("known_user : %s" % known_user) Utils.debug("known_user : %s" % known_user)
Utils.debug("score : %s" % score) Utils.debug("score : %s" % score)
Utils.debug("master_user : %s" % master_user) Utils.debug("master_user : %s" % master_user)
# Store new score for this user
if known_user:
connection.execute("UPDATE rpator SET score=score+1 WHERE name='%s';" % user)
else:
connection.execute("INSERT INTO rpator (name, score) VALUES ('%s', 1);" % user)
# Ok, we got all information we need, let's answer now ! # Ok, we got all information we need, let's answer now !
if master_user: if master_user:
# user is a rp master # user is a rp master
...@@ -787,7 +792,7 @@ class Wantzel(object): ...@@ -787,7 +792,7 @@ class Wantzel(object):
number = int(rows[0][0]) number = int(rows[0][0])
Utils.debug("Found %s articles." % number) Utils.debug("Found %s articles." % number)
if self.number != number: if self.number != number:
self.irc.client.topic("#lqdn-rp", messages["topic"] % number) self.irc.client.topic(RP_CHANNEL, messages["topic"] % number)
self.number = number self.number = number
def rp_to_twitter(self, rss): def rp_to_twitter(self, rss):
......
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