Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
Matrix Gatcha Bot
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki externe
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Déploiement
Releases
Registre de modèles
Analyse
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Ce projet est archivé. Le dépôt et les autres ressources du projet sont en lecture seule.
Afficher davantage de fils d'Ariane
Kubat
Matrix Gatcha Bot
Validations
2408a998
Vérifiée
Valider
2408a998
rédigé
Il y a 3 ans
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Handle reactions (add emoji)
parent
46101732
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
src/matrix.rs
+56
-50
56 ajouts, 50 suppressions
src/matrix.rs
avec
56 ajouts
et
50 suppressions
src/matrix.rs
+
56
−
50
Voir le fichier @
2408a998
use
crate
::{
cmd
::
package
::
CmdPackage
,
cmd
::
Cmd
,
config
::
Config
};
use
crate
::{
cmd
::
package
::
CmdPackage
,
cmd
::
Cmd
,
config
::
Config
,
return_if
};
use
futures
::
future
::
join_all
;
use
log
::{
error
,
info
,
warn
};
use
matrix_sdk
::{
...
...
@@ -6,6 +6,7 @@ use matrix_sdk::{
room
::{
Invited
,
Room
},
ruma
::{
events
::{
reaction
::{
ReactionEventContent
,
Relation
},
room
::{
member
::
MemberEventContent
,
message
::{
MessageEventContent
,
MessageType
,
TextMessageEventContent
},
...
...
@@ -16,7 +17,7 @@ use matrix_sdk::{
},
Client
,
Result
,
SyncSettings
,
};
use
std
::{
convert
::
TryFrom
,
lazy
::
SyncLazy
,
process
::
abort
,
sync
::
Arc
,
sync
::
Mutex
,
time
};
use
std
::{
convert
::
TryFrom
,
lazy
::
SyncLazy
,
process
::
abort
,
sync
::
Arc
,
sync
::
Mutex
};
use
tokio
::
time
::{
sleep
,
Duration
};
async
fn
join_room
(
room
:
&
Invited
)
{
...
...
@@ -97,22 +98,42 @@ pub async fn connect_and_handle(config: Config) -> Result<()> {
};
GLOBAL_PKG
.lock
()
.unwrap
()
.push
(
pkg
);
let
on_msg_room_
event
=
|
ev
:
SyncMessageEvent
<
Message
EventContent
>
,
let
on_msg_room_
reaction
=
|
ev
:
SyncMessageEvent
<
Reaction
EventContent
>
,
room
:
Room
,
_encryption_info
:
Option
<
EncryptionInfo
>
|
async
{
let
now
=
time
::
Instant
::
now
();
let
sender_id
=
ev
.sender
;
if
sender_id
.as_str
()
==
room
.own_user_id
()
.as_str
()
{
return
();
}
_
:
Option
<
EncryptionInfo
>
|
async
move
{
let
sender_id
=
ev
.sender
.clone
();
return_if!
(
sender_id
.as_str
()
==
room
.own_user_id
()
.as_str
(),
());
if
let
(
Room
::
Joined
(
joined
),
ReactionEventContent
{
relates_to
:
Relation
{
emoji
,
event_id
,
..
},
..
},
)
=
(
room
,
ev
.content
)
{
let
msg_content
=
format!
(
"Not handled reactions in room {} with event {event_id}, emoji was {emoji}"
,
joined
.room_id
()
);
let
msg
=
AnyMessageEventContent
::
RoomMessage
(
MessageEventContent
::
text_html
(
msg_content
.clone
(),
msg_content
,
));
joined
.send
(
msg
,
None
)
.await
.unwrap
();
};
};
if
room
.name
()
.is_none
()
{
warn!
(
"Unsupported rooms without names"
);
return
();
}
let
on_msg_room_event
=
|
ev
:
SyncMessageEvent
<
MessageEventContent
>
,
room
:
Room
,
__info
:
Option
<
EncryptionInfo
>
|
async
{
let
sender_id
=
ev
.sender
.clone
();
return_if!
(
sender_id
.as_str
()
==
room
.own_user_id
()
.as_str
(),
());
if
let
Room
::
Joined
(
joined
)
=
room
{
if
let
MessageType
::
Text
(
TextMessageEventContent
{
body
,
..
})
=
ev
.content.msgtype
{
if
let
(
Room
::
Joined
(
joined
),
MessageType
::
Text
(
TextMessageEventContent
{
ref
body
,
..
}))
=
(
room
,
ev
.content.msgtype
.clone
())
{
if
body
.starts_with
(
"%"
)
{
if
let
Some
(
stripped
)
=
body
.strip_prefix
(
"%"
)
{
let
args
=
stripped
.split
(
' '
)
.collect
::
<
Vec
<&
str
>>
();
...
...
@@ -126,30 +147,14 @@ pub async fn connect_and_handle(config: Config) -> Result<()> {
res
=
pkg
.handle
(
&
joined
,
&
sender_id
,
args
);
}
let
event
=
ev
.into_full_event
(
joined
.room_id
()
.clone
());
let
msg
=
AnyMessageEventContent
::
RoomMessage
(
MessageEventContent
::
text_html
(
res
.clone
(),
res
),
MessageEventContent
::
text_
reply_
html
(
res
.clone
(),
res
,
&
event
),
);
let
elapsed_before_send
=
now
.elapsed
();
joined
.send
(
msg
,
None
)
.await
.unwrap
();
let
elapsed_after_send
=
now
.elapsed
();
warn!
(
"Elapsed before send {}µs, elapsed after send {}ms"
,
elapsed_before_send
.as_micros
(),
elapsed_after_send
.as_millis
()
);
}
}
}
}
// if let Room::Invited(_) = room {
// warn!("Bot was invited by {sender_id} to room {room_id} a.k.a. {room_name}",);
// }
// if let Room::Left(_) = room {
// error!("Bot left room {room_id} a.k.a. {room_name}")
// }
return
();
};
};
let
alice
=
UserId
::
try_from
(
config
.user_name
)
?
;
...
...
@@ -176,6 +181,7 @@ pub async fn connect_and_handle(config: Config) -> Result<()> {
}
client
.register_event_handler
(
on_msg_room_event
)
.await
;
client
.register_event_handler
(
on_msg_room_reaction
)
.await
;
info!
(
"Entering sync loop"
);
let
token
=
client
.sync_token
()
.await
.unwrap
();
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter