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
ceb9bb7f
Vérifiée
Valider
ceb9bb7f
rédigé
Il y a 3 ans
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
WIP: Almost there
parent
ec076200
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
4
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
4 fichiers modifiés
src/cmd/mod.rs
+10
-9
10 ajouts, 9 suppressions
src/cmd/mod.rs
src/cmd/package.rs
+1
-0
1 ajout, 0 suppression
src/cmd/package.rs
src/main.rs
+2
-0
2 ajouts, 0 suppression
src/main.rs
src/matrix.rs
+6
-7
6 ajouts, 7 suppressions
src/matrix.rs
avec
19 ajouts
et
16 suppressions
src/cmd/mod.rs
+
10
−
9
Voir le fichier @
ceb9bb7f
...
@@ -2,25 +2,26 @@ pub mod acl;
...
@@ -2,25 +2,26 @@ pub mod acl;
pub
mod
package
;
pub
mod
package
;
use
log
::
error
;
use
log
::
error
;
use
std
::{
process
::
abort
,
string
::
String
};
use
std
::{
process
::
abort
,
string
::
String
,
sync
::
Arc
};
#[allow(dead_code)]
#[allow(dead_code)]
#[derive(Clone)]
enum
CmdHandler
{
enum
CmdHandler
{
Simple
(
Box
<
dyn
Fn
(
Vec
<
String
>
)
->
bool
>
),
Simple
(
Arc
<
dyn
Fn
(
Vec
<
String
>
)
->
bool
>
),
Echo
(
Box
<
dyn
Fn
(
Vec
<
String
>
)
->
String
>
),
Echo
(
Arc
<
dyn
Fn
(
Vec
<
String
>
)
->
String
>
),
MultiEcho
(
Box
<
dyn
Fn
(
Vec
<
String
>
)
->
Vec
<
String
>>
),
MultiEcho
(
Arc
<
dyn
Fn
(
Vec
<
String
>
)
->
Vec
<
String
>>
),
}
}
#[allow(dead_code)]
#[allow(dead_code)]
#[derive(Clone)]
pub
struct
Cmd
{
pub
struct
Cmd
{
name
:
String
,
name
:
String
,
argc
:
u32
,
argc
:
u32
,
handler
:
CmdHandler
,
handler
:
CmdHandler
,
}
}
// unsafe impl Sync for CmdHandler {}
unsafe
impl
Sync
for
Cmd
{}
unsafe
impl
Sync
for
Cmd
{}
//
unsafe impl Send for Cmd {}
unsafe
impl
Send
for
Cmd
{}
impl
Cmd
{
impl
Cmd
{
#[allow(dead_code)]
#[allow(dead_code)]
...
@@ -51,7 +52,7 @@ impl Cmd {
...
@@ -51,7 +52,7 @@ impl Cmd {
}
}
#[allow(dead_code)]
#[allow(dead_code)]
pub
fn
new_simple
(
name
:
String
,
argc
:
u32
,
f
:
Box
<
dyn
Fn
(
Vec
<
String
>
)
->
bool
>
)
->
Cmd
{
pub
fn
new_simple
(
name
:
String
,
argc
:
u32
,
f
:
Arc
<
dyn
Fn
(
Vec
<
String
>
)
->
bool
>
)
->
Cmd
{
Cmd
{
Cmd
{
name
:
name
,
name
:
name
,
argc
:
argc
,
argc
:
argc
,
...
@@ -60,7 +61,7 @@ impl Cmd {
...
@@ -60,7 +61,7 @@ impl Cmd {
}
}
#[allow(dead_code)]
#[allow(dead_code)]
pub
fn
new_echo
(
name
:
String
,
argc
:
u32
,
f
:
Box
<
dyn
Fn
(
Vec
<
String
>
)
->
String
>
)
->
Cmd
{
pub
fn
new_echo
(
name
:
String
,
argc
:
u32
,
f
:
Arc
<
dyn
Fn
(
Vec
<
String
>
)
->
String
>
)
->
Cmd
{
Cmd
{
Cmd
{
name
:
name
,
name
:
name
,
argc
:
argc
,
argc
:
argc
,
...
@@ -72,7 +73,7 @@ impl Cmd {
...
@@ -72,7 +73,7 @@ impl Cmd {
pub
fn
new_multi_echo
(
pub
fn
new_multi_echo
(
name
:
String
,
name
:
String
,
argc
:
u32
,
argc
:
u32
,
f
:
Box
<
dyn
Fn
(
Vec
<
String
>
)
->
Vec
<
String
>>
,
f
:
Arc
<
dyn
Fn
(
Vec
<
String
>
)
->
Vec
<
String
>>
,
)
->
Cmd
{
)
->
Cmd
{
Cmd
{
Cmd
{
name
:
name
,
name
:
name
,
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/cmd/package.rs
+
1
−
0
Voir le fichier @
ceb9bb7f
...
@@ -6,6 +6,7 @@ use ini::Properties as IniSection;
...
@@ -6,6 +6,7 @@ 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
+
2
−
0
Voir le fichier @
ceb9bb7f
#![feature(clone_closures)]
mod
cmd
;
mod
cmd
;
mod
config
;
mod
config
;
mod
matrix
;
mod
matrix
;
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/matrix.rs
+
6
−
7
Voir le fichier @
ceb9bb7f
...
@@ -16,7 +16,7 @@ use matrix_sdk::{
...
@@ -16,7 +16,7 @@ use matrix_sdk::{
},
},
Client
,
Result
,
SyncSettings
,
Client
,
Result
,
SyncSettings
,
};
};
use
std
::{
convert
::
TryFrom
,
process
::
abort
};
use
std
::{
convert
::
TryFrom
,
process
::
abort
,
sync
::
Arc
};
use
tokio
::
time
::{
sleep
,
Duration
};
use
tokio
::
time
::{
sleep
,
Duration
};
async
fn
join_room
(
room
:
&
Invited
)
{
async
fn
join_room
(
room
:
&
Invited
)
{
...
@@ -82,17 +82,16 @@ async fn startup_and_log_rooms(client: &Client) {
...
@@ -82,17 +82,16 @@ async fn startup_and_log_rooms(client: &Client) {
pub
async
fn
connect_and_handle
(
config
:
Config
)
->
Result
<
()
>
{
pub
async
fn
connect_and_handle
(
config
:
Config
)
->
Result
<
()
>
{
// TODO: Refactor
// TODO: Refactor
let
username_copy
=
config
.user_name
.clone
();
let
pkg_commands_vec
=
vec!
[
let
pkg_commands_vec
=
vec!
[
Cmd
::
new_simple
(
format!
(
"ping"
),
0
,
Box
::
new
(|
_x
|
true
)),
Cmd
::
new_simple
(
format!
(
"ping"
),
0
,
Arc
::
new
(|
_x
|
true
)),
Cmd
::
new_echo
(
Cmd
::
new_echo
(
format!
(
"bot_name"
),
format!
(
"bot_name"
),
0
,
0
,
Box
::
new
(
move
|
_x
|
username_copy
.clone
(
)),
Arc
::
new
(
move
|
_x
|
format!
(
"toto"
)),
),
),
];
];
let
pkg
=
match
config
.section
(
"basic"
)
{
let
pkg
=
match
config
.section
(
"basic"
)
{
Some
(
section
)
=>
Box
::
new
(
CmdPackage
::
from_config
(
&
section
,
pkg_commands_vec
)
)
,
Some
(
section
)
=>
CmdPackage
::
from_config
(
&
section
,
pkg_commands_vec
),
None
=>
{
None
=>
{
abort
();
abort
();
}
}
...
@@ -123,7 +122,7 @@ pub async fn connect_and_handle(config: Config) -> Result<()> {
...
@@ -123,7 +122,7 @@ pub async fn connect_and_handle(config: Config) -> Result<()> {
client
client
.register_event_handler
(
.register_event_handler
(
|
ev
:
SyncMessageEvent
<
MessageEventContent
>
,
move
|
ev
:
SyncMessageEvent
<
MessageEventContent
>
,
room
:
Room
,
room
:
Room
,
_encryption_info
:
Option
<
EncryptionInfo
>
|
async
{
_encryption_info
:
Option
<
EncryptionInfo
>
|
async
{
let
sender_id
=
ev
.sender
;
let
sender_id
=
ev
.sender
;
...
@@ -145,7 +144,7 @@ pub async fn connect_and_handle(config: Config) -> Result<()> {
...
@@ -145,7 +144,7 @@ pub async fn connect_and_handle(config: Config) -> Result<()> {
if
body
.starts_with
(
"%"
)
{
if
body
.starts_with
(
"%"
)
{
info!
(
"Got message from {sender_id} in {room_id} a.k.a. {room_name}"
);
info!
(
"Got message from {sender_id} in {room_id} a.k.a. {room_name}"
);
let
args
=
vec!
[];
let
args
=
vec!
[];
let
ret
=
&
pkg
.handle
(
&
joined
,
&
sender_id
,
args
);
let
locked_pkg
=
pkg
.handle
(
&
joined
,
&
sender_id
,
args
);
}
}
}
}
}
}
...
...
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