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é
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
cc286d60
Vérifiée
Valider
cc286d60
rédigé
3 years ago
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Add config to set if the bot should handle events
parent
0a08523e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
3
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
mgb.yml
+5
-1
5 ajouts, 1 suppression
mgb.yml
src/config.rs
+17
-1
17 ajouts, 1 suppression
src/config.rs
src/matrix.rs
+14
-4
14 ajouts, 4 suppressions
src/matrix.rs
avec
36 ajouts
et
6 suppressions
mgb.yml
+
5
−
1
Voir le fichier @
cc286d60
[
user
]
id=@some_id:matrix.org
id=@some_id
\
:matrix.org
password=no-password
display_name=MGB-Hitagi
[
handler
]
state_member=true
room_message=true
Ce diff est replié.
Cliquez pour l'agrandir.
src/config.rs
+
17
−
1
Voir le fichier @
cc286d60
...
...
@@ -2,7 +2,7 @@
use
ini
::{
Error
::
Io
as
IniErrIo
,
Error
::
Parse
as
IniErrParse
,
Ini
};
use
log
::{
error
,
info
,
warn
,
LevelFilter
};
use
std
::{
env
,
path
::
Path
,
process
::
abort
};
use
std
::{
env
,
path
::
Path
,
process
::
abort
,
str
::
FromStr
};
use
url
::
Url
;
pub
struct
Config
{
...
...
@@ -10,6 +10,9 @@ pub struct Config {
pub
homeserver_url
:
Url
,
// The url of the home server, like https://matrix.iiens.net
pub
user_name
:
String
,
// The true user name
pub
user_password
:
String
,
// The true user name
pub
handle_state_member
:
bool
,
// Install handler for state memver changes
pub
handle_room_message
:
bool
,
// Install handler for room messages
}
pub
fn
setup_logging
()
{
...
...
@@ -36,6 +39,12 @@ pub fn from_file(file_name: &String) -> Result<Config, String> {
Err
(
IniErrParse
(
e
))
=>
Err
(
e
.to_string
()),
Ok
(
conf
)
=>
{
let
hs_url_str
=
conf
.get_from_or
(
Some
(
"user"
),
"homeserver"
,
"https://matrix.org"
);
let
handle_room_message_str
=
conf
.get_from_or
(
Some
(
"handler"
),
"room_message"
,
"true"
)
.to_string
();
let
handle_state_member_str
=
conf
.get_from_or
(
Some
(
"handler"
),
"state_member"
,
"true"
)
.to_string
();
return
match
Url
::
parse
(
hs_url_str
)
{
Err
(
e
)
=>
Err
(
e
.to_string
()),
Ok
(
hs_url
)
=>
Ok
(
Config
{
...
...
@@ -49,6 +58,10 @@ pub fn from_file(file_name: &String) -> Result<Config, String> {
.get_from_or
(
Some
(
"user"
),
"display_name"
,
"MGB-Hitagi"
)
.to_string
(),
homeserver_url
:
hs_url
,
handle_room_message
:
<
bool
as
FromStr
>
::
from_str
(
&
handle_room_message_str
)
.unwrap_or
(
false
),
handle_state_member
:
<
bool
as
FromStr
>
::
from_str
(
&
handle_state_member_str
)
.unwrap_or
(
false
),
}),
};
}
...
...
@@ -61,6 +74,9 @@ pub fn write_default(file_name: &String) -> Result<(), String> {
.set
(
"id"
,
"@some_id:matrix.org"
)
.set
(
"password"
,
"no-password"
)
.set
(
"display_name"
,
"MGB-Hitagi"
);
conf
.with_section
(
Some
(
"handler"
))
.set
(
"state_member"
,
"true"
)
.set
(
"room_message"
,
"true"
);
match
conf
.write_to_file_policy
(
file_name
,
ini
::
EscapePolicy
::
Everything
)
{
Ok
(())
=>
{
info!
(
"Default config file written to {}"
,
file_name
);
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/matrix.rs
+
14
−
4
Voir le fichier @
cc286d60
use
crate
::
config
::
Config
;
use
futures
::
{
join
,
future
::
join_all
}
;
use
futures
::
future
::
join_all
;
use
log
::{
error
,
info
,
warn
};
use
matrix_sdk
::{
deserialized_responses
::
EncryptionInfo
,
...
...
@@ -144,9 +144,19 @@ pub async fn connect_and_handle(config: Config) -> Result<()> {
client
.sync_once
(
SyncSettings
::
default
())
.await
?
;
startup_and_log_rooms
(
&
client
)
.await
;
let
register_handle_state
=
client
.register_event_handler
(
on_state_member
);
let
register_handle_message
=
client
.register_event_handler
(
on_room_message
);
join!
(
register_handle_message
,
register_handle_state
);
if
config
.handle_state_member
{
info!
(
"Handle state member events"
);
client
.register_event_handler
(
on_state_member
)
.await
;
}
else
{
warn!
(
"Ignore state member events"
);
}
if
config
.handle_room_message
{
info!
(
"Handle room message events"
);
client
.register_event_handler
(
on_room_message
)
.await
;
}
else
{
error!
(
"Ignore room message events! The bot won't answer to any message"
);
}
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