Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
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
ARISE
matrix-appservice-discord
Validations
0c89347b
Valider
0c89347b
rédigé
Il y a 5 ans
par
Will Hunt
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Fix matrixcommandhandler tests
parent
657f781e
Branches
Branches contenant la validation
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/matrixcommandhandler.ts
+4
-3
4 ajouts, 3 suppressions
src/matrixcommandhandler.ts
test/mocks/appservicemock.ts
+11
-0
11 ajouts, 0 suppression
test/mocks/appservicemock.ts
test/test_matrixcommandhandler.ts
+89
-24
89 ajouts, 24 suppressions
test/test_matrixcommandhandler.ts
avec
104 ajouts
et
27 suppressions
src/matrixcommandhandler.ts
+
4
−
3
Voir le fichier @
0c89347b
...
...
@@ -78,6 +78,7 @@ export class MatrixCommandHandler {
subcat
:
"
m.room.power_levels
"
,
},
run
:
async
({
guildId
,
channelId
})
=>
{
console
.
log
(
roomEntry
);
if
(
roomEntry
&&
roomEntry
.
remote
)
{
return
"
This room is already bridged to a Discord guild.
"
;
}
...
...
@@ -173,11 +174,12 @@ export class MatrixCommandHandler {
};
const
permissionCheck
:
CommandPermissonCheck
=
async
(
permission
)
=>
{
console
.
log
(
"
Wap
"
);
if
(
permission
.
selfService
&&
!
this
.
config
.
bridge
.
enableSelfServiceBridging
)
{
return
"
The owner of this bridge does not permit self-service bridging.
"
;
}
return
await
Util
.
CheckMatrixPermission
(
this
.
bridge
.
bot
Intent
.
underlying
Client
,
this
.
bridge
.
botClient
,
event
.
sender
,
event
.
room_id
,
permission
.
level
,
...
...
@@ -188,8 +190,7 @@ export class MatrixCommandHandler {
const
reply
=
await
Util
.
ParseCommand
(
"
!discord
"
,
event
.
content
!
.
body
!
,
actions
,
parameters
,
permissionCheck
);
const
formattedReply
=
markdown
.
toHTML
(
reply
);
await
this
.
bridge
.
botIntent
.
underlyingClient
.
sendMessage
(
event
.
room_id
,
{
await
this
.
bridge
.
botClient
.
sendMessage
(
event
.
room_id
,
{
body
:
reply
,
format
:
"
org.matrix.custom.html
"
,
formatted_body
:
formattedReply
,
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
test/mocks/appservicemock.ts
+
11
−
0
Voir le fichier @
0c89347b
...
...
@@ -10,6 +10,7 @@ interface IAppserviceMockOpts {
profileFetcher
?:
(
userId
)
=>
Promise
<
any
>
;
botUserId
?:
string
;
userIdPrefix
?:
string
;
joinedrooms
?:
string
[];
}
class
AppserviceMockBase
{
...
...
@@ -60,6 +61,7 @@ class AppserviceMockBase {
export
class
AppserviceMock
extends
AppserviceMockBase
{
public
botIntent
:
IntentMock
;
public
botClient
:
MatrixClientMock
;
public
intents
:
{[
id
:
string
]:
IntentMock
};
public
get
botUserId
():
string
{
...
...
@@ -71,6 +73,7 @@ export class AppserviceMock extends AppserviceMockBase {
opts
.
roommembers
=
opts
.
roommembers
||
[];
this
.
intents
=
{};
this
.
botIntent
=
new
IntentMock
(
this
.
opts
);
this
.
botClient
=
this
.
botIntent
.
underlyingClient
;
}
public
isNamespacedUser
(
userId
:
string
)
{
...
...
@@ -156,6 +159,14 @@ class MatrixClientMock extends AppserviceMockBase {
return
this
.
opts
.
roommembers
;
}
public
getJoinedRooms
()
{
this
.
funcCalled
(
"
getJoinedRooms
"
);
if
(
!
this
.
opts
.
joinedrooms
)
{
throw
Error
(
"
No joinedrooms defined
"
);
}
return
this
.
opts
.
joinedrooms
;
}
public
leaveRoom
(
roomId
:
string
)
{
this
.
funcCalled
(
"
leaveRoom
"
,
roomId
);
}
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
test/test_matrixcommandhandler.ts
+
89
−
24
Voir le fichier @
0c89347b
...
...
@@ -27,9 +27,11 @@ import * as Proxyquire from "proxyquire";
const
expect
=
Chai
.
expect
;
function
createCH
(
opts
:
any
=
{})
{
function
createCH
(
opts
:
any
=
{}
,
shouldBeJoined
=
true
)
{
const
bridge
=
new
AppserviceMock
();
const
bridge
=
new
AppserviceMock
({
joinedrooms
:
shouldBeJoined
?
[
"
!123:localhost
"
]
:
[],
});
const
config
=
new
DiscordBridgeConfig
();
config
.
limits
.
roomGhostJoinDelay
=
0
;
...
...
@@ -95,39 +97,52 @@ function createEvent(msg: string, room?: string, userId?: string) {
function
createContext
(
remoteData
?:
any
)
{
return
{
rooms
:
{
remote
:
remoteData
,
},
};
}
describe
(
"
MatrixCommandHandler
"
,
()
=>
{
describe
(
"
Process
"
,
()
=>
{
it
(
"
should not process command if not in room
"
,
async
()
=>
{
const
{
handler
,
bridge
}
=
createCH
({
disableSS
:
true
}
);
const
{
handler
,
bridge
}
=
createCH
({
},
false
);
await
handler
.
Process
(
createEvent
(
""
,
"
!666:localhost
"
),
createContext
());
bridge
.
botIntent
.
wasNotCalled
(
"
sendText
"
,
true
);
bridge
.
botIntent
.
wasNotCalled
(
"
sendMessage
"
,
true
);
});
it
(
"
should warn if self service is disabled
"
,
async
()
=>
{
const
{
handler
,
bridge
}
=
createCH
({
disableSS
:
true
});
await
handler
.
Process
(
createEvent
(
"
!discord bridge
"
),
createContext
());
const
expected
=
"
**ERROR:** The owner of this bridge does not permit self-service bridging.
"
;
bridge
.
botIntent
.
wasCalled
(
"
sendText
"
,
true
,
"
!123:localhost
"
,
expected
);
bridge
.
botIntent
.
underlyingClient
.
wasCalled
(
"
sendMessage
"
,
true
,
"
!123:localhost
"
,
{
body
:
"
**ERROR:** The owner of this bridge does not permit self-service bridging.
"
,
format
:
"
org.matrix.custom.html
"
,
formatted_body
:
"
<strong>ERROR:</strong> The owner of this bridge does not permit self-service bridging.
"
,
msgtype
:
"
m.notice
"
,
});
});
it
(
"
should warn if user is not powerful enough
"
,
async
()
=>
{
const
{
handler
,
bridge
}
=
createCH
({
power
:
false
});
await
handler
.
Process
(
createEvent
(
"
!discord bridge
"
),
createContext
());
const
expected
=
"
**ERROR:** insufficiant permissions to use this
"
+
"
command! Try `!discord help` to see all available commands
"
;
bridge
.
botIntent
.
wasCalled
(
"
sendText
"
,
true
,
"
!123:localhost
"
,
expected
);
const
htmlExpected
=
"
<strong>ERROR:</strong> insufficiant permissions to use this command! Try <code>!discord help</code> to see all available commands
"
;
bridge
.
botIntent
.
underlyingClient
.
wasCalled
(
"
sendMessage
"
,
true
,
"
!123:localhost
"
,
{
body
:
expected
,
format
:
"
org.matrix.custom.html
"
,
formatted_body
:
htmlExpected
,
msgtype
:
"
m.notice
"
,
});
});
describe
(
"
!discord bridge
"
,
()
=>
{
it
(
"
will bridge a new room, and ask for permissions
"
,
async
()
=>
{
const
{
handler
,
bridge
}
=
createCH
();
await
handler
.
Process
(
createEvent
(
"
!discord bridge 123 456
"
),
createContext
());
const
expected
=
"
I have bridged this room to your channel
"
;
bridge
.
botIntent
.
wasCalled
(
"
sendText
"
,
true
,
"
!123:localhost
"
,
expected
);
bridge
.
botIntent
.
underlyingClient
.
wasCalled
(
"
sendMessage
"
,
true
,
"
!123:localhost
"
,
{
body
:
expected
,
format
:
"
org.matrix.custom.html
"
,
formatted_body
:
expected
,
msgtype
:
"
m.notice
"
,
});
});
it
(
"
will fail to bridge if permissions were denied
"
,
async
()
=>
{
const
{
handler
,
bridge
}
=
createCH
({
...
...
@@ -135,7 +150,12 @@ describe("MatrixCommandHandler", () => {
});
await
handler
.
Process
(
createEvent
(
"
!discord bridge 123 456
"
),
createContext
());
const
expected
=
"
The bridge has been declined by the Discord guild
"
;
bridge
.
botIntent
.
wasCalled
(
"
sendText
"
,
true
,
"
!123:localhost
"
,
expected
);
bridge
.
botIntent
.
underlyingClient
.
wasCalled
(
"
sendMessage
"
,
true
,
"
!123:localhost
"
,
{
body
:
expected
,
format
:
"
org.matrix.custom.html
"
,
formatted_body
:
expected
,
msgtype
:
"
m.notice
"
,
});
});
it
(
"
will fail to bridge if permissions were failed
"
,
async
()
=>
{
const
{
handler
,
bridge
}
=
createCH
({
...
...
@@ -143,31 +163,53 @@ describe("MatrixCommandHandler", () => {
});
await
handler
.
Process
(
createEvent
(
"
!discord bridge 123 456
"
),
createContext
());
const
expected
=
"
There was a problem bridging that channel - has the guild owner approved the bridge?
"
;
bridge
.
botIntent
.
wasCalled
(
"
sendText
"
,
true
,
"
!123:localhost
"
,
expected
);
bridge
.
botIntent
.
underlyingClient
.
wasCalled
(
"
sendMessage
"
,
true
,
"
!123:localhost
"
,
{
body
:
expected
,
format
:
"
org.matrix.custom.html
"
,
formatted_body
:
expected
,
msgtype
:
"
m.notice
"
,
});
});
it
(
"
will not bridge if a link already exists
"
,
async
()
=>
{
const
{
handler
,
bridge
}
=
createCH
();
const
evt
=
await
handler
.
Process
(
createEvent
(
"
!discord bridge 123 456
"
),
createContext
(
true
));
await
handler
.
Process
(
createEvent
(
"
!discord bridge 123 456
"
),
createContext
(
true
));
const
expected
=
"
This room is already bridged to a Discord guild.
"
;
bridge
.
botIntent
.
wasCalled
(
"
sendText
"
,
true
,
"
!123:localhost
"
,
expected
);
bridge
.
botIntent
.
underlyingClient
.
wasCalled
(
"
sendMessage
"
,
true
,
"
!123:localhost
"
,
{
body
:
expected
,
format
:
"
org.matrix.custom.html
"
,
formatted_body
:
expected
,
msgtype
:
"
m.notice
"
,
});
});
it
(
"
will not bridge without required args
"
,
async
()
=>
{
const
{
handler
,
bridge
}
=
createCH
();
const
evt
=
await
handler
.
Process
(
createEvent
(
"
!discord bridge
"
),
createContext
());
const
expected
=
"
Invalid syntax
"
;
bridge
.
botIntent
.
wasCalled
(
"
sendText
"
,
true
,
"
!123:localhost
"
,
expected
);
await
handler
.
Process
(
createEvent
(
"
!discord bridge
"
),
createContext
());
const
expected
=
"
Invalid syntax. For more information try `!discord help bridge`
"
;
const
expectedHtml
=
"
Invalid syntax. For more information try <code>!discord help bridge</code>
"
;
bridge
.
botIntent
.
underlyingClient
.
wasCalled
(
"
sendMessage
"
,
true
,
"
!123:localhost
"
,
{
body
:
expected
,
format
:
"
org.matrix.custom.html
"
,
formatted_body
:
expectedHtml
,
msgtype
:
"
m.notice
"
,
});
});
it
(
"
will bridge with x/y syntax
"
,
async
()
=>
{
const
{
handler
,
bridge
}
=
createCH
({
powerLevels
:
{
users_default
:
100
,
}});
const
evt
=
await
handler
.
Process
(
createEvent
(
"
!discord bridge 123/456
"
),
createContext
());
await
handler
.
Process
(
createEvent
(
"
!discord bridge 123/456
"
),
createContext
());
const
expected
=
"
I have bridged this room to your channel
"
;
bridge
.
botIntent
.
wasCalled
(
"
sendText
"
,
true
,
"
!123:localhost
"
,
expected
);
bridge
.
botIntent
.
underlyingClient
.
wasCalled
(
"
sendMessage
"
,
true
,
"
!123:localhost
"
,
{
body
:
expected
,
format
:
"
org.matrix.custom.html
"
,
formatted_body
:
expected
,
msgtype
:
"
m.notice
"
,
});
});
});
describe
(
"
!discord unbridge
"
,
()
=>
{
it
(
"
will unbridge
"
,
async
()
=>
{
const
expected
=
"
This room has been unbridged
"
;
const
{
handler
,
bridge
}
=
createCH
();
await
handler
.
Process
(
createEvent
(
"
!discord unbridge
"
),
createContext
(
{
...
...
@@ -178,14 +220,26 @@ describe("MatrixCommandHandler", () => {
},
},
));
bridge
.
botIntent
.
wasCalled
(
"
sendText
"
,
true
,
"
!123:localhost
"
,
"
This room has been unbridged
"
);
bridge
.
botIntent
.
underlyingClient
.
wasCalled
(
"
sendMessage
"
,
true
,
"
!123:localhost
"
,
{
body
:
expected
,
format
:
"
org.matrix.custom.html
"
,
formatted_body
:
expected
,
msgtype
:
"
m.notice
"
,
});
});
it
(
"
will not unbridge if a link does not exist
"
,
async
()
=>
{
const
expected
=
"
This room is not bridged.
"
;
const
{
handler
,
bridge
}
=
createCH
();
await
handler
.
Process
(
createEvent
(
"
!discord unbridge
"
),
createContext
());
bridge
.
botIntent
.
wasCalled
(
"
sendText
"
,
true
,
"
!123:localhost
"
,
"
This room is not bridged.
"
);
bridge
.
botIntent
.
underlyingClient
.
wasCalled
(
"
sendMessage
"
,
true
,
"
!123:localhost
"
,
{
body
:
expected
,
format
:
"
org.matrix.custom.html
"
,
formatted_body
:
expected
,
msgtype
:
"
m.notice
"
,
});
});
it
(
"
will not unbridge non-plumbed rooms
"
,
async
()
=>
{
const
expected
=
"
This room cannot be unbridged.
"
;
const
{
handler
,
bridge
}
=
createCH
();
await
handler
.
Process
(
createEvent
(
"
!discord unbridge
"
),
createContext
(
{
...
...
@@ -196,9 +250,15 @@ describe("MatrixCommandHandler", () => {
},
},
));
bridge
.
botIntent
.
wasCalled
(
"
sendText
"
,
true
,
"
!123:localhost
"
,
"
This room cannot be unbridged.
"
);
bridge
.
botIntent
.
underlyingClient
.
wasCalled
(
"
sendMessage
"
,
true
,
"
!123:localhost
"
,
{
body
:
expected
,
format
:
"
org.matrix.custom.html
"
,
formatted_body
:
expected
,
msgtype
:
"
m.notice
"
,
});
});
it
(
"
will show error if unbridge fails
"
,
async
()
=>
{
const
expected
=
"
There was an error unbridging this room. Please try again later or contact the bridge operator.
"
;
const
{
handler
,
bridge
}
=
createCH
({
failUnbridge
:
true
,
});
...
...
@@ -211,7 +271,12 @@ describe("MatrixCommandHandler", () => {
},
},
));
bridge
.
botIntent
.
wasCalled
(
"
sendText
"
,
true
,
"
!123:localhost
"
,
"
There was an error unbridging this room.
"
);
bridge
.
botIntent
.
underlyingClient
.
wasCalled
(
"
sendMessage
"
,
true
,
"
!123:localhost
"
,
{
body
:
expected
,
format
:
"
org.matrix.custom.html
"
,
formatted_body
:
expected
,
msgtype
:
"
m.notice
"
,
});
});
});
});
...
...
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