Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
M
matrix-appservice-discord
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Wiki externe
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneurs
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
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
Afficher davantage de fils d'Ariane
salixor
matrix-appservice-discord
Validations
356849c2
Non vérifiée
Valider
356849c2
rédigé
Il y a 6 ans
par
Sorunome
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
add new tests
parent
95b652e4
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
3
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
src/discordcommandhandler.ts
+16
-0
16 ajouts, 0 suppression
src/discordcommandhandler.ts
src/matrixcommandhandler.ts
+16
-0
16 ajouts, 0 suppression
src/matrixcommandhandler.ts
test/test_util.ts
+143
-26
143 ajouts, 26 suppressions
test/test_util.ts
avec
175 ajouts
et
26 suppressions
src/discordcommandhandler.ts
+
16
−
0
Voir le fichier @
356849c2
/*
Copyright 2019 matrix-appservice-discord
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import
{
DiscordBot
}
from
"
./bot
"
;
import
{
DiscordBot
}
from
"
./bot
"
;
import
*
as
Discord
from
"
discord.js
"
;
import
*
as
Discord
from
"
discord.js
"
;
import
{
Util
,
ICommandActions
,
ICommandParameters
,
CommandPermissonCheck
}
from
"
./util
"
;
import
{
Util
,
ICommandActions
,
ICommandParameters
,
CommandPermissonCheck
}
from
"
./util
"
;
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/matrixcommandhandler.ts
+
16
−
0
Voir le fichier @
356849c2
/*
Copyright 2019 matrix-appservice-discord
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import
{
DiscordBot
}
from
"
./bot
"
;
import
{
DiscordBot
}
from
"
./bot
"
;
import
{
Log
}
from
"
./log
"
;
import
{
Log
}
from
"
./log
"
;
import
{
DiscordBridgeConfig
}
from
"
./config
"
;
import
{
DiscordBridgeConfig
}
from
"
./config
"
;
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
test/test_util.ts
+
143
−
26
Voir le fichier @
356849c2
...
@@ -60,10 +60,11 @@ describe("Util", () => {
...
@@ -60,10 +60,11 @@ describe("Util", () => {
Chai
.
assert
.
equal
(
args
[
1
],
"
arg2
"
);
Chai
.
assert
.
equal
(
args
[
1
],
"
arg2
"
);
});
});
});
});
describe
(
"
ParseCommand
"
,
()
=>
{
describe
(
"
Command Stuff
"
,
()
=>
{
it
(
"
parses commands
"
,
async
()
=>
{
const
actions
:
ICommandActions
=
{
const
actions
:
ICommandActions
=
{
action
:
{
action
:
{
description
:
"
floof
"
,
help
:
"
Fox goes floof!
"
,
params
:
[
"
param1
"
,
"
param2
"
],
params
:
[
"
param1
"
,
"
param2
"
],
run
:
async
({
param1
,
param2
})
=>
{
run
:
async
({
param1
,
param2
})
=>
{
return
`param1:
${
param1
}
\nparam2:
${
param2
}
`
;
return
`param1:
${
param1
}
\nparam2:
${
param2
}
`
;
...
@@ -72,16 +73,51 @@ describe("Util", () => {
...
@@ -72,16 +73,51 @@ describe("Util", () => {
};
};
const
parameters
:
ICommandParameters
=
{
const
parameters
:
ICommandParameters
=
{
param1
:
{
param1
:
{
description
:
"
1
"
,
get
:
async
(
param
:
string
)
=>
{
get
:
async
(
param
:
string
)
=>
{
return
"
param1_
"
+
param
;
return
"
param1_
"
+
param
;
},
},
},
},
param2
:
{
param2
:
{
description
:
"
2
"
,
get
:
async
(
param
:
string
)
=>
{
get
:
async
(
param
:
string
)
=>
{
return
"
param2_
"
+
param
;
return
"
param2_
"
+
param
;
},
},
},
},
};
};
describe
(
"
ParseHelpMessage
"
,
()
=>
{
it
(
"
parses general help message
"
,
async
()
=>
{
const
{
command
,
args
}
=
Util
.
MsgToArgs
(
"
!fox help
"
,
"
!fox
"
);
const
retStr
=
await
Util
.
ParseHelpMessage
(
"
!fox
"
,
actions
,
parameters
,
args
,
);
expect
(
retStr
).
to
.
equal
(
`Available Commands:
-
\`
!fox action <param1> <param2>
\`
: floof
Parameters:
-
\`
<param1>
\`
: 1
-
\`
<param2>
\`
: 2
`
);
});
it
(
"
parses specific help message
"
,
async
()
=>
{
const
{
command
,
args
}
=
Util
.
MsgToArgs
(
"
!fox help action
"
,
"
!fox
"
);
const
retStr
=
await
Util
.
ParseHelpMessage
(
"
!fox
"
,
actions
,
parameters
,
args
,
);
expect
(
retStr
).
to
.
equal
(
`
\`
!fox action <param1> <param2>
\`
: floof
Fox goes floof!`
);
});
});
describe
(
"
ParseCommand
"
,
()
=>
{
it
(
"
parses commands
"
,
async
()
=>
{
const
retStr
=
await
Util
.
ParseCommand
(
const
retStr
=
await
Util
.
ParseCommand
(
"
!fox
"
,
"
!fox
"
,
"
!fox action hello world
"
,
"
!fox action hello world
"
,
...
@@ -91,6 +127,7 @@ describe("Util", () => {
...
@@ -91,6 +127,7 @@ describe("Util", () => {
expect
(
retStr
).
equal
(
"
param1: param1_hello
\n
param2: param2_world
"
);
expect
(
retStr
).
equal
(
"
param1: param1_hello
\n
param2: param2_world
"
);
});
});
});
});
});
describe
(
"
GetMxidFromName
"
,
()
=>
{
describe
(
"
GetMxidFromName
"
,
()
=>
{
it
(
"
Finds a single member
"
,
async
()
=>
{
it
(
"
Finds a single member
"
,
async
()
=>
{
const
mockRooms
=
{
const
mockRooms
=
{
...
@@ -194,4 +231,84 @@ describe("Util", () => {
...
@@ -194,4 +231,84 @@ describe("Util", () => {
expect
(
Date
.
now
()).
to
.
be
.
greaterThan
(
t
+
DELAY_FOR
-
1
);
expect
(
Date
.
now
()).
to
.
be
.
greaterThan
(
t
+
DELAY_FOR
-
1
);
});
});
});
});
describe
(
"
CheckMatrixPermission
"
,
()
=>
{
const
PERM_LEVEL
=
50
;
it
(
"
should deny
"
,
async
()
=>
{
const
ret
=
await
Util
.
CheckMatrixPermission
(
{
getStateEvent
:
async
()
=>
{
return
{
blah
:
{
blubb
:
PERM_LEVEL
,
},
};
},
}
as
any
,
"
@user:localhost
"
,
""
,
PERM_LEVEL
,
"
blah
"
,
"
blubb
"
,
);
expect
(
ret
).
to
.
be
.
false
;
});
it
(
"
should allow cat/subcat
"
,
async
()
=>
{
const
ret
=
await
Util
.
CheckMatrixPermission
(
{
getStateEvent
:
async
()
=>
{
return
{
blah
:
{
blubb
:
PERM_LEVEL
,
},
users
:
{
"
@user:localhost
"
:
PERM_LEVEL
,
},
};
},
}
as
any
,
"
@user:localhost
"
,
""
,
PERM_LEVEL
,
"
blah
"
,
"
blubb
"
,
);
expect
(
ret
).
to
.
be
.
true
;
});
it
(
"
should allow cat
"
,
async
()
=>
{
const
ret
=
await
Util
.
CheckMatrixPermission
(
{
getStateEvent
:
async
()
=>
{
return
{
blah
:
PERM_LEVEL
,
users
:
{
"
@user:localhost
"
:
PERM_LEVEL
,
},
};
},
}
as
any
,
"
@user:localhost
"
,
""
,
PERM_LEVEL
,
"
blah
"
,
);
expect
(
ret
).
to
.
be
.
true
;
});
it
(
"
should allow based on default
"
,
async
()
=>
{
const
ret
=
await
Util
.
CheckMatrixPermission
(
{
getStateEvent
:
async
()
=>
{
return
{
blah
:
PERM_LEVEL
,
users_default
:
PERM_LEVEL
,
};
},
}
as
any
,
"
@user:localhost
"
,
""
,
PERM_LEVEL
,
"
blah
"
,
);
expect
(
ret
).
to
.
be
.
true
;
});
});
});
});
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