Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
s0infodisplay
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kasalehlia
s0infodisplay
Commits
25134500
Commit
25134500
authored
6 years ago
by
Kasalehlia
Browse files
Options
Downloads
Patches
Plain Diff
irc: use own simple implementation
parent
beafd475
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/irc.py
+38
-34
38 additions, 34 deletions
modules/irc.py
with
38 additions
and
34 deletions
modules/irc.py
+
38
−
34
View file @
25134500
import
socket
import
ssl
import
irc.bot
LIMIT
=
35
CACHE_LIMIT
=
35
HOST
=
'
bouncer.ksal.de
'
PORT
=
28921
AUTH_USER
=
'
infodisplay/Freenode
'
AUTH_PW
=
'
Fagee9ie
'
NICK
=
'
infodisplay
'
CHANNEL
=
'
#stratum0
'
class
InfodisplayClient
(
irc
.
bot
.
SingleServerIRCBot
):
def
__init__
(
self
,
emit
,
channel
,
nickname
,
server
,
port
=
6667
):
pw
=
'
Fagee9ie
'
ssl_factory
=
irc
.
connection
.
Factory
(
wrapper
=
ssl
.
wrap_socket
)
irc
.
bot
.
SingleServerIRCBot
.
__init__
(
self
,
[(
server
,
port
,
pw
)],
nickname
,
nickname
,
connect_factory
=
ssl_factory
,
username
=
'
infodisplay/Freenode
'
)
self
.
channel
=
channel
self
.
emit
=
emit
self
.
cache
=
[]
def
on_nicknameinuse
(
self
,
c
,
e
):
c
.
nick
(
c
.
get_nickname
()
+
"
_
"
)
def
on_welcome
(
self
,
c
,
e
):
c
.
join
(
self
.
channel
)
def
on_pubmsg
(
self
,
c
,
e
):
user
=
self
.
_clean_str
(
e
.
source
.
nick
)
if
user
==
'
***
'
:
return
msg
=
self
.
_clean_str
(
e
.
arguments
[
0
])
line
=
'
<p><span>{}</span> {}</p>
'
.
format
(
user
,
msg
)
self
.
cache
.
append
(
line
)
if
len
(
self
.
cache
)
>
LIMIT
:
self
.
cache
.
pop
(
0
)
self
.
emit
(
''
.
join
(
self
.
cache
),
outlet
=
'
inner
'
)
def
_clean_str
(
self
,
s
):
return
s
.
replace
(
'
<
'
,
'
<
'
).
replace
(
'
>
'
,
'
>
'
)
def
_clean_str
(
s
):
return
s
.
replace
(
'
<
'
,
'
<
'
).
replace
(
'
>
'
,
'
>
'
)
def
run
(
emit
,
log_err
):
#TODO log errors
emit
(
'
<h3> IRC #stratum0</h3><div class=
"
chat
"
data-infodisplay-outlet=
"
inner
"
></div>
'
)
bot
=
InfodisplayClient
(
emit
,
'
#stratum0
'
,
'
infodisplay
'
,
'
bouncer.ksal.de
'
,
port
=
28921
)
bot
.
start
()
ctx
=
ssl
.
SSLContext
(
protocol
=
ssl
.
PROTOCOL_TLSv1
)
while
1
:
cache
=
[]
sock
=
socket
.
socket
()
conn
=
ctx
.
wrap_socket
(
sock
)
conn
.
connect
((
HOST
,
PORT
))
fp
=
conn
.
makefile
(
'
rb
'
)
conn
.
write
(
'
PASS {}:{}
\r\n
'
.
format
(
AUTH_USER
,
AUTH_PW
).
encode
())
conn
.
write
(
'
NICK {}
\r\n
USER {} 8 * :{}
\r\n
'
.
format
(
NICK
,
AUTH_USER
,
NICK
).
encode
())
conn
.
write
(
'
JOIN {}
\r\n
'
.
format
(
CHANNEL
).
encode
())
try
:
while
1
:
line
=
fp
.
readline
().
decode
()
source
,
command
,
args
=
line
.
split
(
'
'
,
2
)
if
command
==
'
PRIVMSG
'
and
'
znc@znc.in
'
not
in
source
:
channel
,
message
=
args
.
split
(
'
:
'
,
1
)
sender
=
source
.
split
(
'
!
'
,
1
)[
0
][
1
:]
if
channel
==
CHANNEL
:
out
=
'
<p><span>{}</span> {}</p>
'
.
format
(
sender
,
_clean_str
(
message
))
cache
.
append
(
out
)
if
len
(
cache
)
>
CACHE_LIMIT
:
cache
.
pop
(
0
)
emit
(
''
.
join
(
cache
),
outlet
=
'
inner
'
)
finally
:
log_err
(
'
Connection cycled
'
)
fp
.
close
()
conn
.
close
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment