Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
challenges
ircbot
Commits
e4d464c5
Commit
e4d464c5
authored
May 10, 2022
by
awe
Browse files
removed broken modules and fixed SSL issue
parent
2fe28465
Changes
7
Hide whitespace changes
Inline
Side-by-side
irc/ircserver.py
View file @
e4d464c5
...
...
@@ -21,6 +21,7 @@
from
irc.antiflood
import
AntiFlood
from
botconfig
import
VERBOSE
,
LOG
,
RAW_LOG
from
irc.ircaction
import
recordIrcAction
from
bot
import
kill_bot
from
datetime
import
datetime
import
time
...
...
@@ -115,7 +116,11 @@ class IrcServer:
self
.
log
(
RAW_LOG
,
txt
)
if
self
.
ssl
:
self
.
socket
.
write
(
str
.
encode
(
txt
+
"
\r\n
"
))
try
:
self
.
socket
.
write
(
str
.
encode
(
txt
+
"
\r\n
"
))
except
(
ssl
.
SSLEOFError
,
ssl
.
SSLError
)
as
e
:
self
.
log
(
RAW_LOG
,
"SSL Error occured, killing bot"
)
kill_bot
()
else
:
self
.
socket
.
send
(
str
.
encode
(
txt
+
"
\r\n
"
))
self
.
last_send
=
time
.
time
()
...
...
@@ -123,21 +128,19 @@ class IrcServer:
def
recv
(
self
):
"""
Receive data from the server.
If some messages are left in the messages queue, get the first one instead of recv.
Sometimes the server may send more than one line, that's why we use a queue here, so that this function will
only return one line.
"""
if
self
.
messages
==
[]:
try
:
txt
=
self
.
socket
.
recv
(
1024
).
decode
(
"utf-8"
,
"replace"
)
self
.
messages
+=
filter
(
lambda
x
:
len
(
x
.
strip
())
>
0
,
txt
.
split
(
"
\r\n
"
))
except
socket
.
error
:
raise
socket
.
error
except
:
print
(
"Unexpected error:"
+
str
(
sys
.
exc_info
()[
0
]))
msg
=
self
.
messages
.
pop
(
0
)
txt
=
b
''
msg
=
''
try
:
while
not
txt
.
endswith
(
b
"
\r\n
"
):
txt
+=
self
.
socket
.
recv
(
1
)
msg
=
txt
[:
-
2
].
decode
(
"utf-8"
,
"replace"
)
except
socket
.
error
:
raise
socket
.
error
except
:
print
(
"Unexpected error:"
+
str
(
sys
.
exc_info
()[
0
]))
if
VERBOSE
:
print
(
term
.
colored
(
"Received: "
,
'yellow'
,
attrs
=
[
'bold'
])
+
msg
)
...
...
plugins/challenges/chall.py
deleted
100644 → 0
View file @
2fe28465
# -*- coding: utf8 -*-
# W3-BoT - A modular IRC bot in python3
# Copyright (C) 2011 Adrien Stoffel <awe.email@gmail.com>
#
# This file is part of W3-BoT.
#
# W3-BoT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# W3-BoT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with W3-BoT. If not, see <http://www.gnu.org/licenses/>.
from
plugins.command
import
Command
,
USAGE
from
plugins.commandinfos
import
CommandInfos
from
irc.colors
import
*
import
urllib.parse
import
requests
import
re
class
Chall
(
Command
,
CommandInfos
):
""" Get information about a challenge, based on a part of its name """
def
run
(
self
):
body
=
{
"chall"
:
self
.
params
}
params
=
urllib
.
parse
.
urlencode
(
body
)
url
=
"/irc/chall.php?"
+
params
req
=
requests
.
get
(
"https://w3challs.com"
+
url
)
if
req
.
status_code
!=
200
:
return
(
str
(
req
.
status_code
)
+
" "
+
req
.
reason
)
txt
=
req
.
content
.
decode
()
m
=
re
.
search
(
"^Challenge: \[([^ ]+)\] (.*) by (.*) - note ([^ ]+) (.+). Link: (.+)$"
,
txt
)
if
m
is
not
None
:
format
=
"Challenge: ["
+
bold
(
dark_grey
(
"%s"
))
+
"] "
format
+=
bold
(
"%s"
)
+
" by "
+
bold
(
dark_blue
(
"%s"
))
format
+=
" - note "
+
bold
(
"%s "
)
+
"%s"
format
+=
"
\n
"
+
bold
(
dark_blue
(
"Link: "
))
+
"%s"
txt
=
format
%
(
m
.
group
(
1
),
m
.
group
(
2
),
m
.
group
(
3
),
m
.
group
(
4
),
m
.
group
(
5
),
m
.
group
(
6
))
return
txt
@
classmethod
def
help
(
self
):
return
USAGE
+
"chall [part of challenge name]"
@
classmethod
def
man
(
self
):
return
"chall: get informations about a challenge from a part of it's name"
plugins/challenges/choosechall.py
deleted
100644 → 0
View file @
2fe28465
# -*- coding: utf8 -*-
# W3-BoT - A modular IRC bot in python3
# Copyright (C) 2011 Adrien Stoffel <awe.email@gmail.com>
#
# This file is part of W3-BoT.
#
# W3-BoT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# W3-BoT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with W3-BoT. If not, see <http://www.gnu.org/licenses/>.
from
plugins.command
import
Command
,
USAGE
from
plugins.commandinfos
import
CommandInfos
from
irc.colors
import
*
import
urllib.parse
import
requests
import
re
class
Choosechall
(
Command
,
CommandInfos
):
"""
Choose a challenge on W3Challs for the command sender, that he didn't solve yet.
It takes two optionnal parameters:
- The category ( * == all)
- The pseudo to search for, if different from sender's
"""
def
run
(
self
):
params
=
self
.
params
.
strip
().
rsplit
(
' '
,
2
)
length
=
len
(
params
)
body
=
{
"username"
:
self
.
sender
}
if
length
>
1
:
print
(
params
[
length
-
2
])
if
not
params
[
length
-
2
]
==
'-n'
:
params
=
[
self
.
params
]
else
:
body
[
"username"
]
=
params
[
length
-
1
]
if
length
>
0
and
not
params
[
0
]
==
'-n'
:
body
[
"category"
]
=
params
[
0
]
params
=
urllib
.
parse
.
urlencode
(
body
)
url
=
"/irc/choosechall.php?"
+
params
req
=
requests
.
get
(
"https://w3challs.com"
+
url
)
if
req
.
status_code
!=
200
:
return
(
str
(
req
.
status_code
)
+
" "
+
req
.
reason
)
txt
=
req
.
content
.
decode
()
m
=
re
.
search
(
"^Challenge: \[([^ ]+)\] (.*) by (.*) - note ([^ ]+) (.+). Link: (.+)$"
,
txt
)
if
m
is
not
None
:
format
=
"W3Challenge: ["
+
bold
(
dark_grey
(
"%s"
))
+
"] "
format
+=
bold
(
"%s"
)
+
" by "
+
bold
(
dark_blue
(
"%s"
))
format
+=
" - note "
+
bold
(
"%s "
)
+
"%s"
format
+=
"
\n
"
+
bold
(
dark_blue
(
"Link: "
))
+
"%s"
txt
=
format
%
(
m
.
group
(
1
),
m
.
group
(
2
),
m
.
group
(
3
),
m
.
group
(
4
),
m
.
group
(
5
),
m
.
group
(
6
))
return
txt
@
classmethod
def
help
(
self
):
return
USAGE
+
"choosechall {[-][*|all|cracking|crypto|forensic|hacking|prog|stegano|wargame] } [-n nick]"
@
classmethod
def
man
(
self
):
return
"choosechall: choose a challenge for you on W3Challs"
plugins/challenges/w3c.py
deleted
100644 → 0
View file @
2fe28465
# -*- coding: utf8 -*-
# W3-BoT - A modular IRC bot in python3
# Copyright (C) 2011 Adrien Stoffel <awe.email@gmail.com>
#
# This file is part of W3-BoT.
#
# W3-BoT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# W3-BoT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with W3-BoT. If not, see <http://www.gnu.org/licenses/>.
from
plugins.command
import
Command
,
USAGE
import
urllib.parse
import
requests
class
W3c
(
Command
):
"""
Get statistics of a user on W3Challs.
The statistics of the user that ran the command are returned if arguments were empty.
"""
def
__init__
(
self
,
params
):
Command
.
__init__
(
self
,
params
)
self
.
sender
=
""
def
set_sender
(
self
,
name
):
self
.
sender
=
name
def
run
(
self
):
if
len
(
self
.
params
.
strip
())
==
0
:
username
=
self
.
sender
else
:
username
=
self
.
params
body
=
{
"username"
:
username
}
params
=
urllib
.
parse
.
urlencode
(
body
)
url
=
"/irc/userscore.php?"
+
params
req
=
requests
.
get
(
"https://w3challs.com"
+
url
)
if
req
.
status_code
!=
200
:
return
(
req
.
status_code
+
" "
+
req
.
status_code
).
decode
()
txt
=
req
.
content
.
decode
()
return
txt
@
classmethod
def
help
(
self
):
return
USAGE
+
"w3c username"
@
classmethod
def
man
(
self
):
return
"w3c: Displays the userscore on w3challs for a given user"
plugins/misc/chuck.py
View file @
e4d464c5
...
...
@@ -30,7 +30,7 @@ class Chuck(Command):
""" Get a random Chuck Norris fact! """
def
run
(
self
):
ADDR
=
"http://www.chucknorrisfacts.fr/facts/
alea
"
ADDR
=
"http://www.chucknorrisfacts.fr/facts/
random
"
opener
=
urllib
.
request
.
FancyURLopener
({})
response
=
opener
.
open
(
ADDR
)
...
...
plugins/misc/slogan.py
deleted
100644 → 0
View file @
2fe28465
# -*- coding: utf8 -*-
# W3-BoT - A modular IRC bot in python3
# Copyright (C) 2011 Adrien Stoffel <awe.email@gmail.com>
#
# This file is part of W3-BoT.
#
# W3-BoT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# W3-BoT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with W3-BoT. If not, see <http://www.gnu.org/licenses/>.
from
plugins.command
import
Command
,
USAGE
from
plugins.commandinfos
import
CommandInfos
from
database.database
import
Database
,
DBError
import
re
import
time
import
html
import
random
import
urllib.parse
import
urllib.request
class
Slogan
(
Command
,
CommandInfos
):
""" Create a random slogan """
TYPE_SLOGAN
=
1
TYPE_CINE
=
2
def
run
(
self
):
self
.
type
,
self
.
URL
=
self
.
TYPE_SLOGAN
,
"http://www.sloganazor.com"
self
.
params
=
self
.
params
.
strip
()
if
self
.
params
.
startswith
(
"-c"
):
self
.
params
=
self
.
params
[
2
:].
strip
()
self
.
type
,
self
.
URL
=
self
.
TYPE_CINE
,
"http://www.cinemazor.com"
if
len
(
self
.
params
)
>
0
:
return
self
.
paramSlogan
()
if
self
.
on_private
():
return
"Random slogan is available on channels only."
return
self
.
userSlogan
()
def
rand
(
self
,
array
):
""" Return a random index for a given array """
return
random
.
randint
(
0
,
31337
)
%
len
(
array
)
def
userSlogan
(
self
):
"""
Create a random user slogan.
Chosen users are only those still present on the channel and active during the last hour.
"""
db
=
Database
()
try
:
db
.
query
(
"""
SELECT user
FROM actions
WHERE server=? AND chan=? AND date > ?
AND action = 'PRIVMSG' AND user != ?
"""
,
(
self
.
server
.
get_name
(),
'#'
+
self
.
chan
,
int
(
time
.
time
())
-
60
*
60
,
self
.
botname
,))
users
=
db
.
fetchall
()
except
DBError
as
e
:
return
str
(
e
)
except
Exception
as
e
:
return
"ERROR: "
+
str
(
e
)
user
=
users
.
pop
(
self
.
rand
(
users
))[
0
]
return
self
.
slogan
(
user
)
def
paramSlogan
(
self
):
return
self
.
slogan
(
self
.
params
)
def
slogan
(
self
,
parameters
):
params
=
{
"q"
:
parameters
.
encode
(
"ISO-8859-1"
),
"submit"
:
""
}
data
=
urllib
.
parse
.
urlencode
(
params
).
encode
()
f
=
urllib
.
request
.
urlopen
(
self
.
URL
,
data
)
txt
=
f
.
read
().
decode
(
"utf-8"
,
"replace"
)
if
self
.
type
==
self
.
TYPE_SLOGAN
:
regex
=
""">(?:\s+)([^
\n
]+) <a target='_blank'"""
else
:
regex
=
"""<br>(?:\s+)<br>(?:\s+)([^
\n
]+)<br><br><img src="films/"""
m
=
re
.
search
(
regex
,
txt
,
re
.
S
)
if
m
:
slogan
=
html
.
unescape
(
m
.
group
(
1
))
else
:
slogan
=
'Failed to create a slogan :('
return
slogan
@
classmethod
def
help
(
self
):
return
USAGE
+
"slogan [-c] [params]"
@
classmethod
def
man
(
self
):
return
"slogan: create a random funnny slogan (from a movie with -c option)"
plugins/misc/vdm.py
View file @
e4d464c5
...
...
@@ -43,7 +43,7 @@ class Vdm(Command):
regex
=
'<a href="[^"]+" class="block text-[^"]+">\s*([^
\n
]+)\s*</a>'
m
=
re
.
search
(
regex
,
txt
)
if
m
:
res
=
self
.
remove_html_tags
(
"Aujourd'hui, %s"
%
m
.
group
(
1
))
res
=
self
.
remove_html_tags
(
m
.
group
(
1
))
return
html
.
unescape
(
res
)
return
"[FAIL] regex failed somehow"
...
...
Write
Preview
Supports
Markdown
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