Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
chatat
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
chatat
Commits
2aa8fd00
Kaydet (Commit)
2aa8fd00
authored
May 31, 2019
tarafından
Batuhan Taşkaya
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
channel switching
üst
b99ca815
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
5 deletions
+35
-5
__main__.py
chatat/__main__.py
+26
-5
client.py
chatat/client.py
+9
-0
No files found.
chatat/__main__.py
Dosyayı görüntüle @
2aa8fd00
...
...
@@ -14,6 +14,7 @@ class ChatInterface:
self
.
pubpen
.
subscribe
(
"message"
,
self
.
show_message
)
self
.
pubpen
.
subscribe
(
"new_char"
,
self
.
show_typing
)
self
.
pubpen
.
subscribe
(
"switch_channel"
,
self
.
switch_channel
)
self
.
_buffer
=
""
...
...
@@ -21,6 +22,8 @@ class ChatInterface:
TwitchHelixProtocol
.
session
(
auth
,
self
.
pubpen
.
loop
)
)
self
.
channel
=
None
def
__enter__
(
self
):
self
.
stdscr
=
curses
.
initscr
()
...
...
@@ -79,14 +82,20 @@ class ChatInterface:
char
=
chr
(
await
self
.
pubpen
.
loop
.
run_in_executor
(
None
,
self
.
stdscr
.
getch
))
self
.
pubpen
.
publish
(
"new_char"
,
char
)
def
show_typing
(
self
,
char
):
def
show_typing
(
self
,
char
:
str
):
if
char
==
"
\n
"
:
message
=
Message
.
from_simple
(
Channel
(
"btaskaya"
),
self
.
auth
.
username
,
self
.
_buffer
)
buffer
=
self
.
_buffer
self
.
clear_typing
()
if
buffer
.
startswith
(
":"
):
self
.
_run_cmd
(
buffer
[
1
:])
return
if
self
.
channel
is
None
:
return
message
=
Message
.
from_simple
(
self
.
channel
,
self
.
auth
.
username
,
buffer
)
self
.
pubpen
.
publish
(
"send"
,
message
)
self
.
pubpen
.
publish
(
"message"
,
message
)
self
.
clear_typing
()
return
self
.
input_current_x
+=
1
...
...
@@ -100,6 +109,18 @@ class ChatInterface:
self
.
_buffer
=
""
self
.
input_buffer
.
refresh
()
def
switch_channel
(
self
,
channel
:
Channel
):
self
.
channel
=
channel
def
_run_cmd
(
self
,
cmd
:
str
):
cmd
=
cmd
.
split
(
" "
)
if
"switch"
in
cmd
:
self
.
channel
=
Channel
(
cmd
[
1
])
message
=
Message
.
from_simple
(
"<system>"
,
"<system>"
,
f
"Channel switched to {self.channel}"
)
self
.
pubpen
.
publish
(
"message"
,
message
)
if
__name__
==
"__main__"
:
loop
=
asyncio
.
get_event_loop
()
...
...
chatat/client.py
Dosyayı görüntüle @
2aa8fd00
...
...
@@ -61,6 +61,9 @@ class TwitchChatProtocol(_Protocol, asyncio.Protocol):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
()
.
__init__
(
*
args
,
**
kwargs
)
self
.
pubpen
.
subscribe
(
"send"
,
self
.
_send_to_channel
)
self
.
pubpen
.
subscribe
(
"switch_channel"
,
self
.
_switch_channel
)
self
.
_active_channels
=
[]
def
_send_irc_command
(
self
,
cmd
:
str
,
value
:
str
)
->
None
:
request
=
f
"{cmd.upper()} {value}
\r\n
"
...
...
@@ -69,6 +72,11 @@ class TwitchChatProtocol(_Protocol, asyncio.Protocol):
def
_send_to_channel
(
self
,
message
:
Message
)
->
None
:
self
.
_send_irc_command
(
"privmsg"
,
f
"{message.channel} :{message.message}"
)
def
_switch_channel
(
self
,
channel
:
Channel
)
->
None
:
if
not
channel
in
self
.
_active_channels
:
self
.
_send_irc_command
(
"join"
,
channel
)
self
.
_active_channels
.
append
(
channel
)
def
connection_made
(
self
,
transport
:
asyncio
.
transports
.
Transport
)
->
None
:
# type: ignore
...
...
@@ -81,6 +89,7 @@ class TwitchChatProtocol(_Protocol, asyncio.Protocol):
self
.
logger
.
info
(
f
"Connection made to {ip}:{port}"
)
for
channel
in
self
.
channels
:
self
.
_send_irc_command
(
"join"
,
channel
)
self
.
_active_channels
.
append
(
channel
)
def
data_received
(
self
,
raw_msg
:
bytes
)
->
None
:
data
=
raw_msg
.
decode
()
...
...
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