Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
facebook
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
mautrix
facebook
Commits
11eefd00
Commit
11eefd00
authored
4 years ago
by
Tulir Asokan
Browse files
Options
Downloads
Patches
Plain Diff
Send status notice when auto-refreshing connection
parent
46ce6540
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mautrix_facebook/commands/conn.py
+1
-10
1 addition, 10 deletions
mautrix_facebook/commands/conn.py
mautrix_facebook/user.py
+35
-9
35 additions, 9 deletions
mautrix_facebook/user.py
with
36 additions
and
19 deletions
mautrix_facebook/commands/conn.py
+
1
−
10
View file @
11eefd00
...
@@ -67,13 +67,4 @@ async def ping(evt: CommandEvent) -> None:
...
@@ -67,13 +67,4 @@ async def ping(evt: CommandEvent) -> None:
@command_handler
(
needs_auth
=
True
,
management_only
=
True
,
help_section
=
SECTION_CONNECTION
,
@command_handler
(
needs_auth
=
True
,
management_only
=
True
,
help_section
=
SECTION_CONNECTION
,
help_text
=
"
\"
Refresh
\"
the Facebook Messenger page
"
)
help_text
=
"
\"
Refresh
\"
the Facebook Messenger page
"
)
async
def
refresh
(
evt
:
CommandEvent
)
->
None
:
async
def
refresh
(
evt
:
CommandEvent
)
->
None
:
if
evt
.
sender
.
listener
:
await
evt
.
sender
.
refresh
()
await
evt
.
reply
(
"
Disconnecting Messenger MQTT connection
"
)
evt
.
sender
.
listener
.
disconnect
()
await
evt
.
sender
.
listen_task
await
evt
.
reply
(
"
Refreshing session
"
)
ok
=
await
evt
.
sender
.
load_session
(
_override
=
True
)
if
ok
:
await
evt
.
reply
(
"
Successfully refreshed session
"
)
else
:
await
evt
.
reply
(
"
Failed to refresh session
"
)
This diff is collapsed.
Click to expand it.
mautrix_facebook/user.py
+
35
−
9
View file @
11eefd00
...
@@ -16,11 +16,10 @@
...
@@ -16,11 +16,10 @@
from
typing
import
(
Any
,
Dict
,
Iterator
,
Optional
,
Iterable
,
Type
,
Callable
,
Awaitable
,
from
typing
import
(
Any
,
Dict
,
Iterator
,
Optional
,
Iterable
,
Type
,
Callable
,
Awaitable
,
Union
,
TYPE_CHECKING
)
Union
,
TYPE_CHECKING
)
import
asyncio
import
asyncio
import
logging
import
fbchat
import
fbchat
from
mautrix.types
import
UserID
,
PresenceState
,
RoomID
from
mautrix.types
import
(
UserID
,
PresenceState
,
RoomID
,
EventID
,
TextMessageEventContent
,
from
mautrix.appservice
import
AppService
MessageType
)
from
mautrix.client
import
Client
as
MxClient
from
mautrix.client
import
Client
as
MxClient
from
mautrix.bridge
import
BaseUser
from
mautrix.bridge
import
BaseUser
from
mautrix.bridge._community
import
CommunityHelper
,
CommunityID
from
mautrix.bridge._community
import
CommunityHelper
,
CommunityID
...
@@ -144,17 +143,20 @@ class User(BaseUser):
...
@@ -144,17 +143,20 @@ class User(BaseUser):
return
None
return
None
async
def
load_session
(
self
,
_override
:
bool
=
False
)
->
bool
:
async
def
load_session
(
self
,
_override
:
bool
=
False
,
_raise_errors
:
bool
=
False
)
->
bool
:
if
self
.
_is_logged_in
and
not
_override
:
if
self
.
_is_logged_in
and
not
_override
:
return
True
return
True
elif
not
self
.
_session_data
:
elif
not
self
.
_session_data
:
return
False
return
False
try
:
try
:
session
=
await
fbchat
.
Session
.
from_cookies
(
self
.
_session_data
)
session
=
await
fbchat
.
Session
.
from_cookies
(
self
.
_session_data
)
logged_in
=
await
session
.
is_logged_in
()
except
Exception
:
except
Exception
:
self
.
log
.
exception
(
"
Failed to restore session
"
)
self
.
log
.
exception
(
"
Failed to restore session
"
)
if
_raise_errors
:
raise
return
False
return
False
if
await
session
.
is_
logged_in
()
:
if
logged_in
:
self
.
log
.
info
(
"
Loaded session successfully
"
)
self
.
log
.
info
(
"
Loaded session successfully
"
)
self
.
session
=
session
self
.
session
=
session
self
.
client
=
fbchat
.
Client
(
session
=
self
.
session
)
self
.
client
=
fbchat
.
Client
(
session
=
self
.
session
)
...
@@ -175,11 +177,29 @@ class User(BaseUser):
...
@@ -175,11 +177,29 @@ class User(BaseUser):
# endregion
# endregion
async
def
refresh
(
self
)
->
bool
:
async
def
refresh
(
self
)
->
None
:
event_id
=
None
if
self
.
listener
:
if
self
.
listener
:
event_id
=
await
self
.
send_bridge_notice
(
"
Disconnecting Messenger MQTT connection
"
"
for session refresh...
"
)
self
.
listener
.
disconnect
()
self
.
listener
.
disconnect
()
await
self
.
listen_task
await
self
.
listen_task
return
await
self
.
load_session
(
_override
=
True
)
event_id
=
await
self
.
send_bridge_notice
(
"
Refreshing session...
"
,
edit
=
event_id
)
try
:
ok
=
await
self
.
load_session
(
_override
=
True
,
_raise_errors
=
True
)
except
fbchat
.
FacebookError
as
e
:
await
self
.
send_bridge_notice
(
"
Failed to refresh Messenger session:
"
f
"
{
e
.
message
}
"
,
edit
=
event_id
)
except
Exception
:
await
self
.
send_bridge_notice
(
"
Failed to refresh Messenger session: unknown error
"
"
(see logs for more details)
"
,
edit
=
event_id
)
else
:
if
ok
:
await
self
.
send_bridge_notice
(
"
Successfully refreshed Messenger session
"
,
edit
=
event_id
)
else
:
await
self
.
send_bridge_notice
(
"
Failed to refresh Messenger session:
"
"
not logged in
"
,
edit
=
event_id
)
async
def
logout
(
self
)
->
bool
:
async
def
logout
(
self
)
->
bool
:
ok
=
True
ok
=
True
...
@@ -326,11 +346,17 @@ class User(BaseUser):
...
@@ -326,11 +346,17 @@ class User(BaseUser):
self
.
save
()
self
.
save
()
return
self
.
notice_room
return
self
.
notice_room
async
def
send_bridge_notice
(
self
,
text
:
str
)
->
None
:
async
def
send_bridge_notice
(
self
,
text
:
str
,
edit
:
Optional
[
EventID
]
=
None
)
->
Optional
[
EventID
]:
event_id
=
None
try
:
try
:
await
self
.
az
.
intent
.
send_notice
(
await
self
.
get_notice_room
(),
text
)
content
=
TextMessageEventContent
(
msgtype
=
MessageType
.
NOTICE
,
body
=
text
)
if
edit
:
content
.
set_edit
(
edit
)
event_id
=
await
self
.
az
.
intent
.
send_message
(
await
self
.
get_notice_room
(),
content
)
except
Exception
:
except
Exception
:
self
.
log
.
warning
(
"
Failed to send bridge notice
'
%s
'"
,
text
,
exc_info
=
True
)
self
.
log
.
warning
(
"
Failed to send bridge notice
'
%s
'"
,
text
,
exc_info
=
True
)
return
edit
or
event_id
# region Facebook event handling
# region Facebook event handling
...
...
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