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
62be9245
Valider
62be9245
rédigé
8 years ago
par
Will Hunt
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Clean up to make tslint happy.
parent
d088da41
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/discordbot.ts
+29
-30
29 ajouts, 30 suppressions
src/discordbot.ts
src/matrixroomhandler.ts
+7
-8
7 ajouts, 8 suppressions
src/matrixroomhandler.ts
avec
36 ajouts
et
38 suppressions
src/discordbot.ts
+
29
−
30
Voir le fichier @
62be9245
...
...
@@ -8,7 +8,7 @@ import * as mime from "mime";
export
class
DiscordBot
{
private
config
:
DiscordBridgeConfig
;
private
bot
:
Discord
.
Client
;
private
discord
_u
ser
:
Discord
.
ClientUser
;
private
discord
U
ser
:
Discord
.
ClientUser
;
private
bridge
;
constructor
(
config
:
DiscordBridgeConfig
,
bridge
)
{
this
.
config
=
config
;
...
...
@@ -32,30 +32,29 @@ export class DiscordBot {
return
this
.
bot
;
}
public
LookupRoom
(
server
:
string
,
room
:
string
):
Promise
<
Discord
.
TextChannel
>
{
const
guild
=
this
.
bot
.
guilds
.
find
((
g
)
=>
{
return
(
g
.
id
===
server
||
g
.
name
.
toLowerCase
().
replace
(
/ /g
,
'
-
'
)
===
server
.
toLowerCase
());
return
(
g
.
id
===
server
||
g
.
name
.
toLowerCase
().
replace
(
/ /g
,
"
-
"
)
===
server
.
toLowerCase
());
});
if
(
guild
===
null
)
{
return
Promise
.
reject
(
`Guild
'
${
server
}
'
not found`
);
return
Promise
.
reject
(
`Guild
"
${
server
}
"
not found`
);
}
const
channel
=
guild
.
channels
.
find
((
c
)
=>
{
return
((
c
.
id
===
room
||
c
.
name
.
toLowerCase
().
replace
(
/ /g
,
'
-
'
)
===
room
.
toLowerCase
()
)
&&
c
.
type
===
"
text
"
);
return
((
c
.
id
===
room
||
c
.
name
.
toLowerCase
().
replace
(
/ /g
,
"
-
"
)
===
room
.
toLowerCase
()
)
&&
c
.
type
===
"
text
"
);
});
if
(
channel
===
null
)
{
return
Promise
.
reject
(
`Channel
'
${
room
}
'
not found`
);
return
Promise
.
reject
(
`Channel
"
${
room
}
"
not found`
);
}
return
Promise
.
resolve
(
channel
);
}
public
ProcessMatrixMsgEvent
(
event
,
guild
_i
d
:
string
,
channel
_i
d
:
string
):
Promise
<
any
>
{
public
ProcessMatrixMsgEvent
(
event
,
guild
I
d
:
string
,
channel
I
d
:
string
):
Promise
<
any
>
{
let
chan
;
let
embed
;
const
mxClient
=
this
.
bridge
.
getClientFactory
().
getClientAs
();
return
this
.
LookupRoom
(
guild
_i
d
,
channel
_i
d
).
then
((
channel
)
=>
{
return
this
.
LookupRoom
(
guild
I
d
,
channel
I
d
).
then
((
channel
)
=>
{
chan
=
channel
;
return
mxClient
.
getProfileInfo
(
event
.
sender
);
}).
then
((
profile
)
=>
{
...
...
@@ -77,19 +76,17 @@ export class DiscordBot {
if
([
"
m.image
"
,
"
m.audio
"
,
"
m.video
"
,
"
m.file
"
].
indexOf
(
event
.
content
.
msgtype
)
!==
-
1
)
{
return
Util
.
DownloadFile
(
mxClient
.
mxcUrlToHttp
(
event
.
content
.
url
));
}
else
{
return
Promise
.
resolve
(
null
);
}
}).
then
(
img_buffer
=>
{
if
(
img_buffer
!==
null
)
{
return
Promise
.
resolve
(
null
);
}).
then
((
attachment
)
=>
{
if
(
attachment
!==
null
)
{
return
{
file
:
{
name
:
event
.
content
.
body
,
attachment
:
img_buffer
,
}
attachment
,
}
,
};
}
return
{}
return
{}
;
}).
then
((
opts
)
=>
{
chan
.
sendEmbed
(
embed
,
opts
);
}).
catch
((
err
)
=>
{
...
...
@@ -106,7 +103,7 @@ export class DiscordBot {
discord_channel
:
channel
.
id
,
}).
then
((
rooms
)
=>
{
if
(
rooms
.
length
===
0
)
{
log
.
warn
(
"
DiscordBot
"
,
`Got message but couldn
'
t find room chan id:
${
channel
.
id
}
for it.`
);
log
.
warn
(
"
DiscordBot
"
,
`Got message but couldn
"
t find room chan id:
${
channel
.
id
}
for it.`
);
return
Promise
.
reject
(
"
Room not found.
"
);
}
return
rooms
[
0
].
matrix
.
getId
();
...
...
@@ -117,22 +114,20 @@ export class DiscordBot {
let
remoteUser
:
RemoteUser
;
const
displayName
=
discordUser
.
username
+
"
#
"
+
discordUser
.
discriminator
;
const
id
=
`_discord_
${
discordUser
.
id
}
:
${
this
.
config
.
bridge
.
domain
}
`
;
const
intent
=
this
.
bridge
.
getIntent
(
"
@
"
+
id
);
const
intent
=
this
.
bridge
.
getIntent
(
"
@
"
+
id
);
const
userStore
=
this
.
bridge
.
getUserStore
();
return
userStore
.
getRemoteUser
(
discordUser
.
id
).
then
((
u
)
=>
{
remoteUser
=
u
;
console
.
log
(
remoteUser
);
if
(
remoteUser
===
null
)
{
remoteUser
=
new
RemoteUser
(
discordUser
.
id
);
return
userStore
.
linkUsers
(
new
MatrixUser
(
id
),
remoteUser
remoteUser
,
);
}
return
Promise
.
resolve
();
}).
then
(()
=>
{
console
.
log
(
remoteUser
.
get
(
"
displayname
"
),
"
!==
"
,
displayName
);
if
(
remoteUser
.
get
(
"
displayname
"
)
!==
displayName
)
{
return
intent
.
setDisplayName
(
displayName
).
then
(()
=>
{
remoteUser
.
set
(
"
displayname
"
,
displayName
);
...
...
@@ -141,9 +136,13 @@ export class DiscordBot {
}
return
true
;
}).
then
(()
=>
{
console
.
log
(
remoteUser
.
get
(
"
avatarurl
"
),
"
!==
"
,
discordUser
.
avatarURL
);
if
(
remoteUser
.
get
(
"
avatarurl
"
)
!==
discordUser
.
avatarURL
&&
discordUser
.
avatarURL
!==
null
)
{
return
Util
.
UploadContentFromUrl
(
this
.
bridge
,
discordUser
.
avatarURL
,
intent
,
discordUser
.
avatar
).
then
((
avatar
)
=>
{
return
Util
.
UploadContentFromUrl
(
this
.
bridge
,
discordUser
.
avatarURL
,
intent
,
discordUser
.
avatar
,
).
then
((
avatar
)
=>
{
intent
.
setAvatarUrl
(
avatar
.
mxc_url
).
then
(()
=>
{
remoteUser
.
set
(
"
avatarurl
"
,
discordUser
.
avatarURL
);
return
userStore
.
setRemoteUser
(
remoteUser
);
...
...
@@ -170,17 +169,17 @@ export class DiscordBot {
}).
then
((
room
)
=>
{
const
intent
=
this
.
bridge
.
getIntentFromLocalpart
(
`_discord_
${
msg
.
author
.
id
}
`
);
// Check Attachements
msg
.
attachments
.
forEach
(
attachment
=>
{
Util
.
UploadContentFromUrl
(
this
.
bridge
,
attachment
.
url
,
intent
,
attachment
.
filename
).
then
(
content
=>
{
const
file
_m
ime
=
mime
.
lookup
(
attachment
.
filename
);
msg
.
attachments
.
forEach
(
(
attachment
)
=>
{
Util
.
UploadContentFromUrl
(
this
.
bridge
,
attachment
.
url
,
intent
,
attachment
.
filename
).
then
(
(
content
)
=>
{
const
file
M
ime
=
mime
.
lookup
(
attachment
.
filename
);
const
msgtype
=
attachment
.
height
?
"
m.image
"
:
"
m.file
"
;
const
info
=
{
mimetype
:
file
_m
ime
,
mimetype
:
file
M
ime
,
size
:
attachment
.
filesize
,
w
:
null
,
h
:
null
,
};
if
(
msgtype
==
"
m.image
"
)
{
if
(
msgtype
==
=
"
m.image
"
)
{
info
.
w
=
attachment
.
width
;
info
.
h
=
attachment
.
height
;
}
...
...
@@ -188,11 +187,11 @@ export class DiscordBot {
body
:
attachment
.
filename
,
info
,
msgtype
,
"
url
"
:
content
.
mxc_url
,
url
:
content
.
mxc_url
,
});
});
});
if
(
msg
.
content
!==
null
&&
msg
.
content
!==
""
)
{
if
(
msg
.
content
!==
null
&&
msg
.
content
!==
""
)
{
intent
.
sendText
(
room
,
msg
.
content
);
}
});
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/matrixroomhandler.ts
+
7
−
8
Voir le fichier @
62be9245
...
...
@@ -9,23 +9,23 @@ export class MatrixRoomHandler {
private
config
:
DiscordBridgeConfig
;
private
bridge
:
Bridge
;
private
discord
:
DiscordBot
;
private
alias
_l
ist
:
any
;
private
alias
L
ist
:
any
;
constructor
(
bridge
:
Bridge
,
discord
:
DiscordBot
,
config
:
DiscordBridgeConfig
)
{
this
.
bridge
=
bridge
;
this
.
discord
=
discord
;
this
.
config
=
config
;
this
.
alias
_l
ist
=
{};
this
.
alias
L
ist
=
{};
}
public
OnAliasQueried
(
alias
:
string
,
roomId
:
string
)
{
const
aliasLocalpart
=
alias
.
substr
(
1
,
alias
.
length
-
`:
${
this
.
config
.
bridge
.
domain
}
`
.
length
-
1
);
log
.
info
(
"
MatrixRoomHandler
"
,
`Room created
${
aliasLocalpart
}
=>
${
roomId
}
`
);
if
(
this
.
alias
_l
ist
[
aliasLocalpart
]
==
null
)
{
if
(
this
.
alias
L
ist
[
aliasLocalpart
]
==
null
)
{
log
.
warn
(
"
MatrixRoomHandler
"
,
"
Room was created but we couldn't assign additonal aliases
"
);
return
;
}
const
mxClient
=
this
.
bridge
.
getClientFactory
().
getClientAs
();
this
.
alias
_l
ist
[
aliasLocalpart
].
forEach
((
item
)
=>
{
this
.
alias
L
ist
[
aliasLocalpart
].
forEach
((
item
)
=>
{
if
(
item
===
"
#
"
+
aliasLocalpart
)
{
return
;
}
...
...
@@ -33,12 +33,11 @@ export class MatrixRoomHandler {
log
.
warn
(
"
MatrixRoomHandler
"
,
`Failed to create alias '
${
aliasLocalpart
}
for
${
roomId
}
'`
,
err
);
});
});
delete
this
.
alias
_l
ist
[
aliasLocalpart
];
delete
this
.
alias
L
ist
[
aliasLocalpart
];
}
public
OnEvent
(
request
,
context
)
{
const
event
=
request
.
getData
();
console
.
log
(
"
New Event:
"
,
event
);
if
(
event
.
type
===
"
m.room.message
"
&&
context
.
rooms
.
remote
)
{
let
srvChanPair
=
context
.
rooms
.
remote
.
roomId
.
substr
(
"
_discord
"
.
length
).
split
(
"
_
"
,
2
);
this
.
discord
.
ProcessMatrixMsgEvent
(
event
,
srvChanPair
[
0
],
srvChanPair
[
1
]);
...
...
@@ -73,7 +72,7 @@ export class MatrixRoomHandler {
const
gname
=
channel
.
guild
.
name
.
replace
(
"
"
,
"
-
"
);
const
cname
=
channel
.
name
.
replace
(
"
"
,
"
-
"
);
this
.
alias
_l
ist
[
alias
]
=
[
this
.
alias
L
ist
[
alias
]
=
[
`#_discord_
${
channel
.
guild
.
id
}
#
${
channel
.
id
}
:
${
this
.
config
.
bridge
.
domain
}
`
,
`#_discord_
${
channel
.
guild
.
id
}
#
${
cname
}
:
${
this
.
config
.
bridge
.
domain
}
`
,
`#_discord_
${
gname
}
#
${
channel
.
id
}
:
${
this
.
config
.
bridge
.
domain
}
`
,
...
...
@@ -94,7 +93,7 @@ export class MatrixRoomHandler {
join_rule
:
"
public
"
,
},
state_key
:
""
,
}
}
,
// }, {
// type: "org.matrix.twitter.data",
// content: user,
...
...
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