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
8974cb27
Vérifiée
Valider
8974cb27
rédigé
3 years ago
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Refactor: split the connect_and_handle function
parent
2ad38687
Aucune branche associée trouvée
Branches contenant la validation
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
4
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
4 fichiers modifiés
src/cmd/mod.rs
+23
-24
23 ajouts, 24 suppressions
src/cmd/mod.rs
src/cmd/package.rs
+0
-1
0 ajout, 1 suppression
src/cmd/package.rs
src/main.rs
+3
-2
3 ajouts, 2 suppressions
src/main.rs
src/matrix.rs
+3
-3
3 ajouts, 3 suppressions
src/matrix.rs
avec
29 ajouts
et
30 suppressions
src/cmd/mod.rs
+
23
−
24
Voir le fichier @
8974cb27
...
@@ -4,16 +4,18 @@ pub mod acl;
...
@@ -4,16 +4,18 @@ pub mod acl;
pub
mod
package
;
pub
mod
package
;
use
log
::
error
;
use
log
::
error
;
use
std
::{
process
::
abort
,
string
::
String
,
sync
::
Arc
};
use
std
::{
boxed
::
Box
,
process
::
abort
,
string
::
String
};
trait
CmdFnSimple
=
Fn
(
Vec
<&
str
>
)
->
bool
+
Send
+
Sync
;
trait
CmdFnEcho
=
Fn
(
Vec
<&
str
>
)
->
String
+
Send
+
Sync
;
trait
CmdFnMultiEcho
=
Fn
(
Vec
<&
str
>
)
->
Vec
<
String
>
+
Send
+
Sync
;
#[derive(Clone)]
enum
CmdHandler
{
enum
CmdHandler
{
Simple
(
Arc
<
dyn
Fn
(
Vec
<&
str
>
)
->
bool
+
Send
+
Sync
>
),
Simple
(
Box
<
dyn
CmdFnSimple
>
),
Echo
(
Arc
<
dyn
Fn
(
Vec
<&
str
>
)
->
String
+
Send
+
Sync
>
),
Echo
(
Box
<
dyn
CmdFnEcho
>
),
MultiEcho
(
Arc
<
dyn
Fn
(
Vec
<&
str
>
)
->
Vec
<
String
>
+
Send
+
Sync
>
),
MultiEcho
(
Box
<
dyn
CmdFnMultiEcho
>
),
}
}
#[derive(Clone)]
pub
struct
Cmd
{
pub
struct
Cmd
{
name
:
String
,
name
:
String
,
argc
:
u32
,
argc
:
u32
,
...
@@ -45,39 +47,36 @@ impl Cmd {
...
@@ -45,39 +47,36 @@ impl Cmd {
&
self
.name
&
self
.name
}
}
pub
fn
new_simple
(
pub
fn
new_simple
<
F
:
'static
>
(
name
:
String
,
argc
:
u32
,
f
:
F
)
->
Cmd
name
:
String
,
where
argc
:
u32
,
F
:
Fn
(
Vec
<&
str
>
)
->
bool
+
Send
+
Sync
,
f
:
Arc
<
dyn
Fn
(
Vec
<&
str
>
)
->
bool
+
Send
+
Sync
>
,
{
)
->
Cmd
{
Cmd
{
Cmd
{
name
:
name
,
name
:
name
,
argc
:
argc
,
argc
:
argc
,
handler
:
CmdHandler
::
Simple
(
f
),
handler
:
CmdHandler
::
Simple
(
Box
::
new
(
f
)
),
}
}
}
}
pub
fn
new_echo
(
pub
fn
new_echo
<
F
:
'static
>
(
name
:
String
,
argc
:
u32
,
f
:
F
)
->
Cmd
name
:
String
,
where
argc
:
u32
,
F
:
Fn
(
Vec
<&
str
>
)
->
String
+
Send
+
Sync
,
f
:
Arc
<
dyn
Fn
(
Vec
<&
str
>
)
->
String
+
Send
+
Sync
>
,
{
)
->
Cmd
{
Cmd
{
Cmd
{
name
:
name
,
name
:
name
,
argc
:
argc
,
argc
:
argc
,
handler
:
CmdHandler
::
Echo
(
f
),
handler
:
CmdHandler
::
Echo
(
Box
::
new
(
f
)
),
}
}
}
}
pub
fn
new_multi_echo
(
pub
fn
new_multi_echo
<
F
:
'static
>
(
name
:
String
,
argc
:
u32
,
f
:
F
)
->
Cmd
name
:
String
,
where
argc
:
u32
,
F
:
Fn
(
Vec
<&
str
>
)
->
Vec
<
String
>
+
Send
+
Sync
,
f
:
Arc
<
dyn
Fn
(
Vec
<&
str
>
)
->
Vec
<
String
>
+
Send
+
Sync
>
,
{
)
->
Cmd
{
Cmd
{
Cmd
{
name
:
name
,
name
:
name
,
argc
:
argc
,
argc
:
argc
,
handler
:
CmdHandler
::
MultiEcho
(
f
),
handler
:
CmdHandler
::
MultiEcho
(
Box
::
new
(
f
)
),
}
}
}
}
}
}
Ce diff est replié.
Cliquez pour l'agrandir.
src/cmd/package.rs
+
0
−
1
Voir le fichier @
8974cb27
...
@@ -6,7 +6,6 @@ use ini::Properties as IniSection;
...
@@ -6,7 +6,6 @@ use ini::Properties as IniSection;
use
matrix_sdk
::{
room
::
Joined
as
JoinedRoom
,
ruma
::
UserId
};
use
matrix_sdk
::{
room
::
Joined
as
JoinedRoom
,
ruma
::
UserId
};
use
std
::{
convert
::
TryFrom
,
fmt
};
use
std
::{
convert
::
TryFrom
,
fmt
};
#[derive(Clone)]
pub
struct
CmdPackage
{
pub
struct
CmdPackage
{
name
:
String
,
name
:
String
,
acl
:
CmdAcl
,
acl
:
CmdAcl
,
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/main.rs
+
3
−
2
Voir le fichier @
8974cb27
#![feature(new_uninit,
once_cell)]
#![feature(new_uninit,
once_cell
,
trait_alias
)]
mod
cmd
;
mod
cmd
;
mod
config
;
mod
config
;
...
@@ -20,7 +20,8 @@ async fn main() -> matrix_sdk::Result<()> {
...
@@ -20,7 +20,8 @@ async fn main() -> matrix_sdk::Result<()> {
];
];
matrix
::
Bot
::
new
(
env
::
args
()
.last
()
.unwrap
())
matrix
::
Bot
::
new
(
env
::
args
()
.last
()
.unwrap
())
.connect
()
.await
?
.connect
()
.await
?
.add_package
(
format!
(
"basic"
),
basic_cmds
)
.add_package
(
format!
(
"basic"
),
basic_cmds
)
.listen
()
.listen
()
.await
.await
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/matrix.rs
+
3
−
3
Voir le fichier @
8974cb27
...
@@ -232,7 +232,7 @@ impl Bot {
...
@@ -232,7 +232,7 @@ impl Bot {
}
}
pub
fn
add_package
(
&
self
,
name
:
String
,
cmds
:
Vec
<
Cmd
>
)
->
&
Self
{
pub
fn
add_package
(
&
self
,
name
:
String
,
cmds
:
Vec
<
Cmd
>
)
->
&
Self
{
let
pkg
=
match
self
.config
.section
(
"basic"
)
{
let
pkg
=
match
self
.config
.section
(
&
name
)
{
Some
(
section
)
=>
CmdPackage
::
from_config
(
&
section
,
cmds
),
Some
(
section
)
=>
CmdPackage
::
from_config
(
&
section
,
cmds
),
None
=>
{
None
=>
{
abort
();
abort
();
...
@@ -245,8 +245,8 @@ impl Bot {
...
@@ -245,8 +245,8 @@ impl Bot {
pub
async
fn
connect_and_handle
(
config
:
Config
)
->
Result
<
()
>
{
pub
async
fn
connect_and_handle
(
config
:
Config
)
->
Result
<
()
>
{
// TODO: Refactor
// TODO: Refactor
let
pkg_commands_vec
=
vec!
[
let
pkg_commands_vec
=
vec!
[
Cmd
::
new_simple
(
format!
(
"ping"
),
0
,
Arc
::
new
(
|
_x
|
true
)
)
,
Cmd
::
new_simple
(
format!
(
"ping"
),
0
,
|
_x
|
true
),
Cmd
::
new_echo
(
format!
(
"bot_name"
),
0
,
Arc
::
new
(
move
|
_x
|
format!
(
"toto"
))
)
,
Cmd
::
new_echo
(
format!
(
"bot_name"
),
0
,
|
_x
|
format!
(
"toto"
)),
];
];
let
pkg
=
match
config
.section
(
"basic"
)
{
let
pkg
=
match
config
.section
(
"basic"
)
{
Some
(
section
)
=>
CmdPackage
::
from_config
(
&
section
,
pkg_commands_vec
),
Some
(
section
)
=>
CmdPackage
::
from_config
(
&
section
,
pkg_commands_vec
),
...
...
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