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
0b8e25a7
Valider
0b8e25a7
rédigé
Il y a 7 ans
par
Andrew Morgan andrew@amorgan.xyz
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Add support for custom discord emojis.
parent
f4929b67
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/matrixeventprocessor.ts
+25
-0
25 ajouts, 0 suppression
src/matrixeventprocessor.ts
src/messageprocessor.ts
+2
-1
2 ajouts, 1 suppression
src/messageprocessor.ts
test/test_matrixeventprocessor.ts
+1
-0
1 ajout, 0 suppression
test/test_matrixeventprocessor.ts
avec
28 ajouts
et
1 suppression
src/matrixeventprocessor.ts
+
25
−
0
Voir le fichier @
0b8e25a7
...
@@ -11,6 +11,8 @@ import * as log from "npmlog";
...
@@ -11,6 +11,8 @@ import * as log from "npmlog";
const
MaxFileSize
=
8000000
;
const
MaxFileSize
=
8000000
;
const
MIN_NAME_LENGTH
=
2
;
const
MIN_NAME_LENGTH
=
2
;
const
MAX_NAME_LENGTH
=
32
;
const
MAX_NAME_LENGTH
=
32
;
const
DISCORD_EMOJI_REGEX
=
/:
(\w
+
)
:/g
;
export
class
MatrixEventProcessorOpts
{
export
class
MatrixEventProcessorOpts
{
constructor
(
constructor
(
readonly
config
:
DiscordBridgeConfig
,
readonly
config
:
DiscordBridgeConfig
,
...
@@ -45,6 +47,10 @@ export class MatrixEventProcessor {
...
@@ -45,6 +47,10 @@ export class MatrixEventProcessor {
if
(
this
.
config
.
bridge
.
disableHereMention
)
{
if
(
this
.
config
.
bridge
.
disableHereMention
)
{
body
=
body
.
replace
(
new
RegExp
(
`@here`
,
"
g
"
),
"
@ here
"
);
body
=
body
.
replace
(
new
RegExp
(
`@here`
,
"
g
"
),
"
@ here
"
);
}
}
// Handle discord custom emoji
body
=
this
.
ReplaceDiscordEmoji
(
body
,
channel
.
guild
);
let
displayName
=
event
.
sender
;
let
displayName
=
event
.
sender
;
let
avatarUrl
=
undefined
;
let
avatarUrl
=
undefined
;
if
(
profile
)
{
if
(
profile
)
{
...
@@ -92,6 +98,25 @@ export class MatrixEventProcessor {
...
@@ -92,6 +98,25 @@ export class MatrixEventProcessor {
return
body
;
return
body
;
}
}
public
ReplaceDiscordEmoji
(
content
:
string
,
guild
:
Discord
.
Guild
):
string
{
console
.
log
(
"
Gonna replace
"
)
let
results
=
DISCORD_EMOJI_REGEX
.
exec
(
content
);
while
(
results
!==
null
)
{
const
emojiName
=
results
[
1
];
const
emojiNameWithColons
=
results
[
0
];
// Check if this emoji exists in the guild
if
(
guild
.
emojis
[
emojiName
]
!==
null
)
{
// Replace :a: with <:a:123ID123>
const
emojiID
=
guild
.
emojis
.
find
((
emoji
)
=>
{
return
emoji
.
name
===
emojiName
}).
id
;
content
=
content
.
replace
(
emojiNameWithColons
,
`<
${
emojiNameWithColons
}${
emojiID
}
>`
);
}
results
=
DISCORD_EMOJI_REGEX
.
exec
(
content
);
}
return
content
;
}
public
async
HandleAttachment
(
event
:
any
,
mxClient
:
any
):
Promise
<
string
|
Discord
.
FileOptions
>
{
public
async
HandleAttachment
(
event
:
any
,
mxClient
:
any
):
Promise
<
string
|
Discord
.
FileOptions
>
{
const
hasAttachment
=
[
const
hasAttachment
=
[
"
m.image
"
,
"
m.image
"
,
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/messageprocessor.ts
+
2
−
1
Voir le fichier @
0b8e25a7
...
@@ -25,7 +25,6 @@ export class MessageProcessorOpts {
...
@@ -25,7 +25,6 @@ export class MessageProcessorOpts {
constructor
(
readonly
domain
:
string
,
readonly
bot
:
DiscordBot
=
null
)
{
constructor
(
readonly
domain
:
string
,
readonly
bot
:
DiscordBot
=
null
)
{
}
}
}
}
export
class
MessageProcessorMatrixResult
{
export
class
MessageProcessorMatrixResult
{
...
@@ -163,7 +162,9 @@ export class MessageProcessor {
...
@@ -163,7 +162,9 @@ export class MessageProcessor {
`Could not insert emoji
${
id
}
for msg
${
msg
.
id
}
in guild
${
msg
.
guild
.
id
}
:
${
ex
}
`
,
`Could not insert emoji
${
id
}
for msg
${
msg
.
id
}
in guild
${
msg
.
guild
.
id
}
:
${
ex
}
`
,
);
);
}
}
results
=
EMOJI_REGEX
.
exec
(
content
);
results
=
EMOJI_REGEX
.
exec
(
content
);
}
}
return
content
;
return
content
;
}
}
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
test/test_matrixeventprocessor.ts
+
1
−
0
Voir le fichier @
0b8e25a7
...
@@ -204,6 +204,7 @@ describe("MatrixEventProcessor", () => {
...
@@ -204,6 +204,7 @@ describe("MatrixEventProcessor", () => {
},
{
avatar_url
:
"
test
"
},
mockChannel
as
any
);
},
{
avatar_url
:
"
test
"
},
mockChannel
as
any
);
Chai
.
assert
.
equal
(
evt
.
description
,
"
@ here Hello!
"
);
Chai
.
assert
.
equal
(
evt
.
description
,
"
@ here Hello!
"
);
});
});
// TODO: Add a test for replaceDiscordEmoji
});
});
describe
(
"
FindMentionsInPlainBody
"
,
()
=>
{
describe
(
"
FindMentionsInPlainBody
"
,
()
=>
{
it
(
"
processes mentioned username correctly
"
,
async
()
=>
{
it
(
"
processes mentioned username correctly
"
,
async
()
=>
{
...
...
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