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 conteneur
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é
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
salixor
matrix-appservice-discord
Validations
41062cb0
Non vérifiée
Valider
41062cb0
rédigé
6 years ago
par
Sorunome
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
add tests
parent
89904ad0
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
src/matrixeventprocessor.ts
+1
-1
1 ajout, 1 suppression
src/matrixeventprocessor.ts
test/test_matrixeventprocessor.ts
+76
-2
76 ajouts, 2 suppressions
test/test_matrixeventprocessor.ts
avec
77 ajouts
et
3 suppressions
src/matrixeventprocessor.ts
+
1
−
1
Voir le fichier @
41062cb0
...
@@ -210,7 +210,7 @@ export class MatrixEventProcessor {
...
@@ -210,7 +210,7 @@ export class MatrixEventProcessor {
replyEmbed
.
addField
(
"
ping
"
,
`<@
${
uid
}
>`
);
replyEmbed
.
addField
(
"
ping
"
,
`<@
${
uid
}
>`
);
}
}
replyEmbed
.
t
imestamp
=
new
Date
(
sourceEvent
.
origin_server_ts
);
replyEmbed
.
setT
imestamp
(
new
Date
(
sourceEvent
.
origin_server_ts
)
)
;
return
replyEmbed
;
return
replyEmbed
;
}
catch
(
ex
)
{
}
catch
(
ex
)
{
log
.
warn
(
"
Failed to handle reply, showing a unknown embed:
"
,
ex
);
log
.
warn
(
"
Failed to handle reply, showing a unknown embed:
"
,
ex
);
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
test/test_matrixeventprocessor.ts
+
76
−
2
Voir le fichier @
41062cb0
...
@@ -16,6 +16,8 @@ import { IMatrixEvent } from "../src/matrixtypes";
...
@@ -16,6 +16,8 @@ import { IMatrixEvent } from "../src/matrixtypes";
// we are a test file and thus need those
// we are a test file and thus need those
/* tslint:disable:no-unused-expression max-file-line-count no-any */
/* tslint:disable:no-unused-expression max-file-line-count no-any */
const
TEST_TIMESTAMP
=
1337
;
const
expect
=
Chai
.
expect
;
const
expect
=
Chai
.
expect
;
// const assert = Chai.assert;
// const assert = Chai.assert;
const
bot
=
{
const
bot
=
{
...
@@ -63,7 +65,7 @@ function createMatrixEventProcessor(): MatrixEventProcessor {
...
@@ -63,7 +65,7 @@ function createMatrixEventProcessor(): MatrixEventProcessor {
const
bridge
=
{
const
bridge
=
{
getBot
:
()
=>
{
getBot
:
()
=>
{
return
{
return
{
isRemoteUser
:
()
=>
false
,
isRemoteUser
:
(
s
)
=>
s
.
includes
(
"
@_discord_
"
)
,
};
};
},
},
getClientFactory
:
()
=>
{
getClientFactory
:
()
=>
{
...
@@ -88,6 +90,7 @@ function createMatrixEventProcessor(): MatrixEventProcessor {
...
@@ -88,6 +90,7 @@ function createMatrixEventProcessor(): MatrixEventProcessor {
content
:
{
content
:
{
body
:
"
Hello!
"
,
body
:
"
Hello!
"
,
},
},
origin_server_ts
:
TEST_TIMESTAMP
,
sender
:
"
@doggo:localhost
"
,
sender
:
"
@doggo:localhost
"
,
};
};
}
else
if
(
eventId
===
"
$reply:localhost
"
)
{
}
else
if
(
eventId
===
"
$reply:localhost
"
)
{
...
@@ -114,6 +117,13 @@ function createMatrixEventProcessor(): MatrixEventProcessor {
...
@@ -114,6 +117,13 @@ function createMatrixEventProcessor(): MatrixEventProcessor {
},
},
sender
:
"
@doggo:localhost
"
,
sender
:
"
@doggo:localhost
"
,
};
};
}
else
if
(
eventId
===
"
$discord:localhost
"
)
{
return
{
content
:
{
body
:
"
Foxies
"
,
},
sender
:
"
@_discord_1234:localhost
"
,
};
}
}
return
null
;
return
null
;
},
},
...
@@ -137,6 +147,11 @@ function createMatrixEventProcessor(): MatrixEventProcessor {
...
@@ -137,6 +147,11 @@ function createMatrixEventProcessor(): MatrixEventProcessor {
return
Buffer
.
alloc
(
size
);
return
Buffer
.
alloc
(
size
);
},
},
});
});
const
discordbot
=
{
GetDiscordUserOrMember
:
async
(
s
)
=>
{
return
new
Discord
.
User
({
}
as
any
,
{
username
:
"
Someuser
"
});
},
};
return
new
(
Proxyquire
(
"
../src/matrixeventprocessor
"
,
{
return
new
(
Proxyquire
(
"
../src/matrixeventprocessor
"
,
{
"
./util
"
:
{
"
./util
"
:
{
...
@@ -146,7 +161,7 @@ function createMatrixEventProcessor(): MatrixEventProcessor {
...
@@ -146,7 +161,7 @@ function createMatrixEventProcessor(): MatrixEventProcessor {
new
MatrixEventProcessorOpts
(
new
MatrixEventProcessorOpts
(
config
,
config
,
bridge
,
bridge
,
{}
as
any
,
discordbot
as
any
,
));
));
}
}
const
mockChannel
=
new
MockChannel
();
const
mockChannel
=
new
MockChannel
();
...
@@ -416,6 +431,23 @@ describe("MatrixEventProcessor", () => {
...
@@ -416,6 +431,23 @@ describe("MatrixEventProcessor", () => {
}
as
IMatrixEvent
,
mockChannel
as
any
);
}
as
IMatrixEvent
,
mockChannel
as
any
);
Chai
.
assert
.
equal
(
embeds
.
messageEmbed
.
description
,
""
);
Chai
.
assert
.
equal
(
embeds
.
messageEmbed
.
description
,
""
);
});
});
it
(
"
Should ping the user on discord replies
"
,
async
()
=>
{
const
processor
=
createMatrixEventProcessor
();
const
embeds
=
await
processor
.
EventToEmbed
({
content
:
{
"
body
"
:
"
Bunnies
"
,
"
m.relates_to
"
:
{
"
m.in_reply_to
"
:
{
event_id
:
"
$discord:localhost
"
,
},
},
"
url
"
:
"
mxc://bunny
"
,
},
sender
:
"
@test:localhost
"
,
type
:
"
m.room.member
"
,
}
as
IMatrixEvent
,
mockChannel
as
any
);
Chai
.
assert
.
equal
(
embeds
.
messageEmbed
.
description
,
"
Bunnies
\n
(<@1234>)
"
);
});
});
});
describe
(
"
HandleAttachment
"
,
()
=>
{
describe
(
"
HandleAttachment
"
,
()
=>
{
const
SMALL_FILE
=
200
;
const
SMALL_FILE
=
200
;
...
@@ -627,5 +659,47 @@ This is the reply`,
...
@@ -627,5 +659,47 @@ This is the reply`,
expect
(
result
!
.
author
!
.
icon_url
).
to
.
be
.
equal
(
"
https://fakeurl.com
"
);
expect
(
result
!
.
author
!
.
icon_url
).
to
.
be
.
equal
(
"
https://fakeurl.com
"
);
expect
(
result
!
.
author
!
.
url
).
to
.
be
.
equal
(
"
https://matrix.to/#/@doggo:localhost
"
);
expect
(
result
!
.
author
!
.
url
).
to
.
be
.
equal
(
"
https://matrix.to/#/@doggo:localhost
"
);
});
});
it
(
"
should add the reply time
"
,
async
()
=>
{
const
processor
=
createMatrixEventProcessor
();
const
result
=
await
processor
.
GetEmbedForReply
({
content
:
{
"
body
"
:
"
Test
"
,
"
m.relates_to
"
:
{
"
m.in_reply_to
"
:
{
event_id
:
"
$goodEvent:localhost
"
,
},
},
},
sender
:
"
@test:localhost
"
,
type
:
"
m.room.message
"
,
}
as
IMatrixEvent
,
mockChannel
as
any
);
expect
(
result
!
.
timestamp
!
.
getTime
()).
to
.
be
.
equal
(
TEST_TIMESTAMP
);
});
it
(
"
should add field for discord replies
"
,
async
()
=>
{
const
processor
=
createMatrixEventProcessor
();
const
result
=
await
processor
.
GetEmbedForReply
({
content
:
{
"
body
"
:
"
foxfoxfox
"
,
"
m.relates_to
"
:
{
"
m.in_reply_to
"
:
{
event_id
:
"
$discord:localhost
"
,
},
},
},
sender
:
"
@test:localhost
"
,
type
:
"
m.room.message
"
,
}
as
IMatrixEvent
,
mockChannel
as
any
);
let
foundField
=
false
;
// tslint:disable-next-line prefer-for-of
for
(
let
i
=
0
;
i
<
result
!
.
fields
!
.
length
;
i
++
)
{
const
f
=
result
!
.
fields
!
[
i
];
if
(
f
.
name
===
"
ping
"
)
{
foundField
=
true
;
expect
(
f
.
value
).
to
.
be
.
equal
(
"
<@1234>
"
);
break
;
}
}
expect
(
foundField
).
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