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
2d5da2a9
Vérifiée
Valider
2d5da2a9
rédigé
3 years ago
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Fix most unused imports
parent
e146d12e
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
src/config.rs
+8
-4
8 ajouts, 4 suppressions
src/config.rs
src/main.rs
+2
-10
2 ajouts, 10 suppressions
src/main.rs
src/matrix.rs
+35
-24
35 ajouts, 24 suppressions
src/matrix.rs
avec
45 ajouts
et
38 suppressions
src/config.rs
+
8
−
4
Voir le fichier @
2d5da2a9
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
use
ini
::{
Error
::
Io
as
IniErrIo
,
Error
::
Parse
as
IniErrParse
,
Ini
};
use
ini
::{
Error
::
Io
as
IniErrIo
,
Error
::
Parse
as
IniErrParse
,
Ini
};
use
log
::{
error
,
info
,
warn
,
LevelFilter
};
use
log
::{
error
,
info
,
warn
,
LevelFilter
};
use
std
::{
env
,
path
::
Path
,
process
::
abort
};
use
url
::
Url
;
use
url
::
Url
;
use
std
::{
process
::
abort
,
path
::
Path
,
env
};
pub
struct
Config
{
pub
struct
Config
{
pub
display_name
:
String
,
// The display name to set for the bot
pub
display_name
:
String
,
// The display name to set for the bot
...
@@ -61,9 +61,12 @@ pub fn write_default(file_name: &String) -> Result<(), String> {
...
@@ -61,9 +61,12 @@ pub fn write_default(file_name: &String) -> Result<(), String> {
.set
(
"id"
,
"@some_id:matrix.org"
)
.set
(
"id"
,
"@some_id:matrix.org"
)
.set
(
"password"
,
"no-password"
)
.set
(
"password"
,
"no-password"
)
.set
(
"display_name"
,
"MGB-Hitagi"
);
.set
(
"display_name"
,
"MGB-Hitagi"
);
return
match
conf
.write_to_file_policy
(
file_name
,
ini
::
EscapePolicy
::
Everything
)
{
match
conf
.write_to_file_policy
(
file_name
,
ini
::
EscapePolicy
::
Everything
)
{
Ok
(())
=>
Ok
(()),
Ok
(())
=>
{
Err
(
e
)
=>
Err
(
e
.to_string
()),
info!
(
"Default config file written to {}"
,
file_name
);
return
Ok
(());
}
Err
(
e
)
=>
return
Err
(
e
.to_string
()),
};
};
}
}
...
@@ -84,6 +87,7 @@ pub fn check_argument_or_abort(should_write_default: bool) {
...
@@ -84,6 +87,7 @@ pub fn check_argument_or_abort(should_write_default: bool) {
);
);
abort
();
abort
();
}
else
if
should_write_default
{
}
else
if
should_write_default
{
warn!
(
"Try to write the default config file to {}"
,
default_file
);
match
write_default
(
&
default_file
)
{
match
write_default
(
&
default_file
)
{
Ok
(())
=>
error!
(
Ok
(())
=>
error!
(
"Args count is {}, you need to only specify the config file for the bot.
\
"Args count is {}, you need to only specify the config file for the bot.
\
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/main.rs
+
2
−
10
Voir le fichier @
2d5da2a9
#![allow(unused_imports)]
mod
config
;
mod
config
;
mod
matrix
;
mod
matrix
;
use
crate
::
config
::
Config
;
use
log
::{
error
,
info
,
warn
};
use
log4rs
;
// use log4rs::config::{Appender, Config, Logger, Root};
use
log
::{
error
,
info
};
use
matrix_sdk
;
use
matrix_sdk
;
use
std
::
convert
::
TryFrom
;
use
std
::{
env
,
process
::
abort
};
use
std
::
path
::
Path
;
use
std
::{
env
,
process
::
exit
,
process
::
abort
};
#[tokio::main]
#[tokio::main]
async
fn
main
()
->
matrix_sdk
::
Result
<
()
>
{
async
fn
main
()
->
matrix_sdk
::
Result
<
()
>
{
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/matrix.rs
+
35
−
24
Voir le fichier @
2d5da2a9
...
@@ -5,16 +5,12 @@ use matrix_sdk::{
...
@@ -5,16 +5,12 @@ use matrix_sdk::{
room
::
Room
,
room
::
Room
,
ruma
::{
ruma
::{
events
::{
events
::{
macros
::
EventContent
,
push_rules
::
PushRulesEvent
,
room
::
message
::{
MessageEventContent
,
MessageType
,
TextMessageEventContent
},
room
::
message
::{
MessageEventContent
,
MessageType
,
TextMessageEventContent
},
room
::
topic
::
TopicEventContent
,
AnyMessageEventContent
,
SyncMessageEvent
,
AnyMessageEventContent
,
AnyRoomEvent
,
AnySyncRoomEvent
,
StateEvent
,
SyncMessageEvent
,
SyncStateEvent
,
},
},
Int
,
MilliSecondsSinceUnixEpoch
,
UserId
,
UserId
,
},
},
Client
,
LoopCtrl
,
Result
,
RoomInfo
,
SyncSettings
,
Client
,
Result
,
RoomInfo
,
SyncSettings
,
};
};
use
std
::
convert
::
TryFrom
;
use
std
::
convert
::
TryFrom
;
...
@@ -29,24 +25,39 @@ async fn on_room_message(
...
@@ -29,24 +25,39 @@ async fn on_room_message(
return
;
return
;
}
}
if
let
Room
::
Joined
(
room
)
=
room
{
let
room_name
=
match
room
.name
()
{
let
room_name
=
match
room
.name
()
{
Some
(
n
)
=>
"<"
.to_string
()
+
&
n
+
">"
,
Some
(
n
)
=>
"<"
.to_string
()
+
&
n
+
">"
,
None
=>
"<--none-->"
.to_string
(),
None
=>
"<--none-->"
.to_string
(),
};
};
let
_body
=
match
ev
.content.msgtype
{
match
room
{
MessageType
::
Text
(
TextMessageEventContent
{
body
,
..
})
=>
"Text: "
.to_string
()
+
&
body
,
Room
::
Joined
(
room
)
=>
{
_
=>
"Unsupported type"
.to_string
(),
let
_body
=
match
ev
.content.msgtype
{
};
MessageType
::
Text
(
TextMessageEventContent
{
body
,
..
})
=>
{
info!
(
"Text: "
.to_string
()
+
&
body
"{} a.k.a. {}, from {}"
,
}
_
=>
"Unsupported type"
.to_string
(),
};
info!
(
"Got message from {} in {} a.k.a. {}"
,
sender_id
,
room
.room_id
(),
room_name
);
// room.send(
// AnyMessageEventContent::RoomMessage(MessageEventContent::text_plain("Hello world")),
// None,
// )
// .await
// .unwrap();
}
Room
::
Invited
(
room
)
=>
warn!
(
"Bot was invited by {} to room {} a.k.a. {}"
,
sender_id
,
room
.room_id
(),
room
.room_id
(),
room_name
,
room_name
sender_id
),
);
Room
::
Left
(
room
)
=>
error!
(
"Bot left room {} a.k.a. {}"
,
room
.room_id
(),
room_name
),
let
content
=
AnyMessageEventContent
::
RoomMessage
(
MessageEventContent
::
text_plain
(
"Hello world"
));
room
.send
(
content
,
None
)
.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