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
a1c6fffe
Vérifiée
Valider
a1c6fffe
rédigé
3 years ago
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Use the new Config module
parent
9fb998b3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
src/main.rs
+51
-33
51 ajouts, 33 suppressions
src/main.rs
avec
51 ajouts
et
33 suppressions
src/main.rs
+
51
−
33
Voir le fichier @
a1c6fffe
#![allow(unused_imports)]
#![allow(unused_imports)]
extern
crate
ini
;
mod
config
;
use
crate
::
config
::
Config
;
use
ini
::
Ini
;
use
matrix_sdk
::{
use
matrix_sdk
::{
ruma
::{
ruma
::{
events
::{
room
::
message
::
MessageEventContent
,
SyncMessageEvent
},
events
::{
room
::
message
::
MessageEventContent
,
SyncMessageEvent
},
...
@@ -10,48 +10,62 @@ use matrix_sdk::{
...
@@ -10,48 +10,62 @@ use matrix_sdk::{
},
},
Client
,
Result
,
SyncSettings
,
Client
,
Result
,
SyncSettings
,
};
};
use
std
::
path
::
Path
;
use
std
::
convert
::
TryFrom
;
use
std
::
convert
::
TryFrom
;
use
std
::{
env
,
process
::
exit
};
use
std
::{
env
,
process
::
exit
};
use
url
::
Url
;
/* a def conf creation (TODO):
let mut conf = Ini::new();
conf.with_section(None::<String>)
.set("encoding", "utf-8");
conf.with_section(Some("User"))
.set("given_name", "Tommy")
.set("family_name", "Green")
.set("unicode", "Raspberry树莓");
conf.with_section(Some("Book"))
.set("name", "Rust cool");
conf.write_to_file("conf.ini").unwrap();
*/
#[tokio::main]
#[tokio::main]
async
fn
main
()
->
Result
<
()
>
{
async
fn
main
()
->
Result
<
()
>
{
let
config_file
=
"conf.ini"
;
// TODO
if
env
::
args
()
.len
()
!=
2
{
let
default_file
=
env
::
args
()
let
conf
=
Ini
::
load_from_file
(
config_file
)
.unwrap
();
.nth
(
0
)
let
user_conf
=
conf
.section
(
Some
(
"user"
))
.unwrap
();
.unwrap
()
let
user_id
=
user_conf
.get
(
"id"
)
.unwrap
();
.split
(
std
::
path
::
MAIN_SEPARATOR
)
let
user_token
=
user_conf
.get
(
"password"
)
.unwrap
();
.last
()
let
homeserver
=
user_conf
.get
(
"homeserver"
)
.unwrap
();
.unwrap
()
.to_string
()
+
".yml"
;
if
Path
::
new
(
&
default_file
)
.exists
()
{
panic!
(
"Args count is {}, you need to only specify the config file for the bot"
,
env
::
args
()
.len
()
-
1
);
}
else
{
match
config
::
write_default
(
&
default_file
)
{
Ok
(())
=>
panic!
(
"Args count is {}, you need to only specify the config file for the bot.
\
The default config file was written to '{}'"
,
env
::
args
()
.len
()
-
1
,
default_file
),
Err
(
e
)
=>
panic!
(
"Args count is {}, you need to only specify the config file for the bot.
\
The default config file '{}' could not be written: {}"
,
env
::
args
()
.len
()
-
1
,
default_file
,
e
),
}
}
}
let
alice
=
UserId
::
try_from
(
user_id
)
?
;
let
config_file
=
env
::
args
()
.last
()
.unwrap
();
println!
(
"User id created: {}"
,
alice
);
return
match
Url
::
parse
(
homeserver
)
{
return
match
config
::
from_file
(
&
config_file
)
{
Err
(
e
)
=>
panic!
(
"Invalid homeserver url: {}"
,
e
),
Ok
(
config
)
=>
{
Ok
(
homeserver_url
)
=>
{
let
alice
=
UserId
::
try_from
(
config
.user_name
)
?
;
println!
(
"Try to login to: {}"
,
homeserver_url
);
let
client
=
Client
::
new
(
config
.homeserver_url
)
?
;
let
client
=
Client
::
new
(
homeserver_url
)
?
;
client
client
.login
(
alice
.localpart
(),
user_token
,
None
,
Some
(
"Test BOT"
))
.login
(
alice
.localpart
(),
config
.user_password
.as_str
(),
None
,
Some
(
config
.display_name
.as_str
()),
)
.await
?
;
.await
?
;
println!
(
"Logged in! Try to register event handler"
);
client
client
.register_event_handler
(|
ev
:
SyncMessageEvent
<
MessageEventContent
>
|
async
move
{
.register_event_handler
(|
ev
:
SyncMessageEvent
<
MessageEventContent
>
|
async
move
{
println!
(
"Received a message {:?}"
,
ev
);
println!
(
"Received a message {:?}"
,
ev
);
...
@@ -61,5 +75,9 @@ async fn main() -> Result<()> {
...
@@ -61,5 +75,9 @@ async fn main() -> Result<()> {
client
.sync
(
SyncSettings
::
default
())
.await
;
// Should never return
client
.sync
(
SyncSettings
::
default
())
.await
;
// Should never return
Ok
(())
Ok
(())
}
}
Err
(
e
)
=>
panic!
(
"Failed to read config file '{}' with error: {}"
,
config_file
,
e
),
};
};
}
}
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