Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wantzel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
9
Issues
9
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
La Quadrature du Net
rpteam
wantzel
Commits
08e4ec67
Commit
08e4ec67
authored
Oct 30, 2016
by
Mindiell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing bugs
parent
2868f4d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
31 deletions
+36
-31
create_sqlite_base.sql
create_sqlite_base.sql
+2
-2
wantzel.py
wantzel.py
+34
-29
No files found.
create_sqlite_base.sql
View file @
08e4ec67
...
...
@@ -6,8 +6,8 @@ INSERT INTO moderator VALUES ('Mindiell');
CREATE
TABLE
tweets
(
last_entry_published
varchar
(
40
));
INSERT
INTO
tweets
VALUES
(
'2015-01-01 00:00:00 UTC'
);
CREATE
TABLE
wiki
(
last_entry_publish
ed
varchar
(
40
));
INSERT
INTO
wiki
VALUES
(
'2015-01-01 00:00:00 UTC'
);
CREATE
TABLE
wiki
s
(
last_entry_updat
ed
varchar
(
40
));
INSERT
INTO
wiki
s
VALUES
(
'2015-01-01 00:00:00 UTC'
);
CREATE
TABLE
rpator
(
name
varchar
(
50
),
score
int
);
wantzel.py
View file @
08e4ec67
...
...
@@ -30,6 +30,8 @@ LOG_LEVEL = DEBUG
MASTER_SCORE
=
5
MASTER_CLEANING
=
7
# in days
RP_CHANNEL
=
"#mytipy"
animals
=
[
{
"left"
:
"""><((('>"""
,
...
...
@@ -193,8 +195,8 @@ class Wantzel(object):
next_week
.
tm_mday
,
time
.
tzname
[
0
]
),
"%Y-%m-%d %Z"
)
# Sequence for op_mode verification
self
.
op_sequence
=
[
2
,
3
,
5
,
8
,
13
,
21
,
34
,
55
]
# Sequence for op_mode verification
(fibonacci)
self
.
op_sequence
=
[
1
,
2
,
3
,
5
,
8
,
13
,
21
,
34
,
55
]
self
.
op_offset
=
0
self
.
op_counter
=
0
# Number of articles actually waiting
...
...
@@ -242,7 +244,7 @@ class Wantzel(object):
# Tell on channel if wiki was modified since last time
self
.
wiki_updates
()
# Cleaning points of mastering rp
if
time
.
localtime
()
>
next_cleaning
:
if
time
.
localtime
()
>
self
.
next_cleaning
:
self
.
clean_master_rp
()
# Recalling the timer
reactor
.
callLater
(
config
.
timer
,
self
.
timer
)
...
...
@@ -269,7 +271,8 @@ class Wantzel(object):
if
flag_set
:
# thanks to user
self
.
send_message
(
channel
,
messages
[
"oped"
]
%
user
)
# reset sequence
# reset counter and sequence
self
.
op_counter
=
0
self
.
op_offset
=
0
else
:
# bad user ;o(
...
...
@@ -280,32 +283,23 @@ class Wantzel(object):
Verify if wantzel is chan operator, if not it complains on the chan <3.
"""
Utils
.
debug
(
"op_verification method"
)
# Testing based on fibonacci sequence
self
.
op_counter
+=
1
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"
)
# Bot tries to list channel users, if it can't, then it is no more an op
self
.
irc
.
client
.
sendLine
(
"NAMES %s"
%
RP_CHANNEL
)
def
irc_unknown
(
self
,
prefix
,
command
,
params
):
"""
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.
"""
Utils
.
debug
(
"UNKNOWN %s %s %s"
%
(
prefix
,
command
,
params
))
if
command
==
"RPL_NAMREPLY"
:
# Beg for operator mode
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
):
"""
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[0]:
- params[1]:
...
...
@@ -313,10 +307,21 @@ class Wantzel(object):
- params[3]: the list of all users on the channel
"""
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
]
==
"@"
]
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
):
"""
...
...
@@ -497,24 +502,24 @@ class Wantzel(object):
# Retrieve user's score in database
connection
=
sqlite3
.
connect
(
config
.
sqlite_db
)
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
score
=
int
(
row
[
0
])
if
score
>
MASTER_SCORE
:
master_user
=
True
# Store new score for this user
if
known_user
:
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"
:
# Channel is RP_CHANNEL, so the user is knowing the rp yet
if
channel
==
RP_CHANNEL
:
know_rp
=
True
Utils
.
debug
(
"know_rp : %s"
%
know_rp
)
Utils
.
debug
(
"known_user : %s"
%
known_user
)
Utils
.
debug
(
"score : %s"
%
score
)
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 !
if
master_user
:
# user is a rp master
...
...
@@ -787,7 +792,7 @@ class Wantzel(object):
number
=
int
(
rows
[
0
][
0
])
Utils
.
debug
(
"Found %s articles."
%
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
def
rp_to_twitter
(
self
,
rss
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment