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
45a7841b
Valider
45a7841b
rédigé
8 years ago
par
Will Hunt
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Begin to add support for bridged rooms.
parent
e840da4d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
3
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
src/bot.ts
+49
-34
49 ajouts, 34 suppressions
src/bot.ts
src/dbschema/dbschema.ts
+1
-1
1 ajout, 1 suppression
src/dbschema/dbschema.ts
src/matrixroomhandler.ts
+2
-0
2 ajouts, 0 suppression
src/matrixroomhandler.ts
avec
52 ajouts
et
35 suppressions
src/bot.ts
+
49
−
34
Voir le fichier @
45a7841b
...
@@ -2,7 +2,7 @@ import { DiscordBridgeConfig } from "./config";
...
@@ -2,7 +2,7 @@ import { DiscordBridgeConfig } from "./config";
import
{
DiscordClientFactory
}
from
"
./clientfactory
"
;
import
{
DiscordClientFactory
}
from
"
./clientfactory
"
;
import
{
DiscordStore
}
from
"
./store
"
;
import
{
DiscordStore
}
from
"
./store
"
;
import
{
DiscordDMHandler
}
from
"
./dmhandler
"
;
import
{
DiscordDMHandler
}
from
"
./dmhandler
"
;
import
{
MatrixUser
,
RemoteUser
,
Bridge
,
RemoteRoom
}
from
"
matrix-appservice-bridge
"
;
import
{
MatrixUser
,
RemoteUser
,
Bridge
,
RemoteRoom
,
Entry
}
from
"
matrix-appservice-bridge
"
;
import
{
Util
}
from
"
./util
"
;
import
{
Util
}
from
"
./util
"
;
import
*
as
Discord
from
"
discord.js
"
;
import
*
as
Discord
from
"
discord.js
"
;
import
*
as
log
from
"
npmlog
"
;
import
*
as
log
from
"
npmlog
"
;
...
@@ -47,7 +47,7 @@ export class DiscordBot {
...
@@ -47,7 +47,7 @@ export class DiscordBot {
client
.
on
(
"
typingStart
"
,
(
c
,
u
)
=>
{
this
.
OnTyping
(
c
,
u
,
true
);
});
client
.
on
(
"
typingStart
"
,
(
c
,
u
)
=>
{
this
.
OnTyping
(
c
,
u
,
true
);
});
client
.
on
(
"
typingStop
"
,
(
c
,
u
)
=>
{
this
.
OnTyping
(
c
,
u
,
false
);
});
client
.
on
(
"
typingStop
"
,
(
c
,
u
)
=>
{
this
.
OnTyping
(
c
,
u
,
false
);
});
client
.
on
(
"
userUpdate
"
,
(
_
,
newUser
)
=>
{
this
.
UpdateUser
(
newUser
);
});
client
.
on
(
"
userUpdate
"
,
(
_
,
newUser
)
=>
{
this
.
UpdateUser
(
newUser
);
});
client
.
on
(
"
channelUpdate
"
,
(
_
,
newChannel
)
=>
{
this
.
UpdateRoom
(
<
Discord
.
TextChannel
>
newChannel
);
});
client
.
on
(
"
channelUpdate
"
,
(
_
,
newChannel
)
=>
{
this
.
UpdateRoom
s
(
<
Discord
.
TextChannel
>
newChannel
);
});
client
.
on
(
"
presenceUpdate
"
,
(
_
,
newMember
)
=>
{
this
.
UpdatePresence
(
newMember
);
});
client
.
on
(
"
presenceUpdate
"
,
(
_
,
newMember
)
=>
{
this
.
UpdatePresence
(
newMember
);
});
client
.
on
(
"
message
"
,
(
msg
)
=>
{
Bluebird
.
delay
(
MSG_PROCESS_DELAY
).
then
(()
=>
{
client
.
on
(
"
message
"
,
(
msg
)
=>
{
Bluebird
.
delay
(
MSG_PROCESS_DELAY
).
then
(()
=>
{
this
.
OnMessage
(
msg
);
this
.
OnMessage
(
msg
);
...
@@ -152,7 +152,6 @@ export class DiscordBot {
...
@@ -152,7 +152,6 @@ export class DiscordBot {
}).
then
((
attachment
)
=>
{
}).
then
((
attachment
)
=>
{
if
(
attachment
!==
null
)
{
if
(
attachment
!==
null
)
{
let
name
=
this
.
GetFilenameForMediaEvent
(
event
.
content
);
let
name
=
this
.
GetFilenameForMediaEvent
(
event
.
content
);
console
.
log
(
name
);
return
{
return
{
file
:
{
file
:
{
name
,
name
,
...
@@ -187,7 +186,7 @@ export class DiscordBot {
...
@@ -187,7 +186,7 @@ export class DiscordBot {
return
"
matrix-media.
"
+
mime
.
extension
(
content
.
info
.
mimetype
);
return
"
matrix-media.
"
+
mime
.
extension
(
content
.
info
.
mimetype
);
}
}
private
GetRoomIdFromChannel
(
channel
:
Discord
.
Channel
):
Promise
<
string
>
{
private
GetRoomId
s
FromChannel
(
channel
:
Discord
.
Channel
):
Promise
<
string
[]
>
{
return
this
.
bridge
.
getRoomStore
().
getEntriesByRemoteRoomData
({
return
this
.
bridge
.
getRoomStore
().
getEntriesByRemoteRoomData
({
discord_channel
:
channel
.
id
,
discord_channel
:
channel
.
id
,
}).
then
((
rooms
)
=>
{
}).
then
((
rooms
)
=>
{
...
@@ -195,36 +194,45 @@ export class DiscordBot {
...
@@ -195,36 +194,45 @@ export class DiscordBot {
log
.
verbose
(
"
DiscordBot
"
,
`Got message but couldn"t find room chan id:
${
channel
.
id
}
for it.`
);
log
.
verbose
(
"
DiscordBot
"
,
`Got message but couldn"t find room chan id:
${
channel
.
id
}
for it.`
);
return
Promise
.
reject
(
"
Room not found.
"
);
return
Promise
.
reject
(
"
Room not found.
"
);
}
}
return
rooms
[
0
]
.
matrix
.
getId
();
return
rooms
.
map
((
room
)
=>
{
return
room
.
matrix
.
getId
();
});
});
});
}
}
private
UpdateRoom
(
discordChannel
:
Discord
.
TextChannel
):
Promise
<
null
>
{
private
UpdateRoom
s
(
discordChannel
:
Discord
.
TextChannel
):
Promise
<
null
>
{
const
intent
=
this
.
bridge
.
getIntent
();
const
intent
=
this
.
bridge
.
getIntent
();
const
roomStore
=
this
.
bridge
.
getRoomStore
();
const
roomStore
=
this
.
bridge
.
getRoomStore
();
let
entry
:
RemoteRoom
;
return
this
.
GetRoomIdsFromChannel
(
discordChannel
).
then
((
rooms
)
=>
{
let
roomId
=
null
;
return
roomStore
.
getEntriesByMatrixIds
(
rooms
).
then
(
(
entries
)
=>
{
return
this
.
GetRoomIdFromChannel
(
discordChannel
).
then
((
r
)
=>
{
return
Object
.
keys
(
entries
).
map
((
key
)
=>
entries
[
key
]);
roomId
=
r
;
});
return
roomStore
.
getEntriesByMatrixId
(
roomId
);
}).
then
((
entries
:
any
)
=>
{
}).
then
((
entries
)
=>
{
return
Promise
.
all
(
entries
.
map
((
entry
)
=>
{
if
(
entries
.
length
===
0
)
{
if
(
entry
.
length
===
0
)
{
return
Promise
.
reject
(
"
Couldn't update room for channel, no assoicated entry in roomstore.
"
);
return
Promise
.
reject
(
"
Couldn't update room for channel, no assoicated entry in roomstore.
"
);
}
}
entry
=
entries
[
0
];
return
this
.
UpdateRoomEntry
(
entry
[
0
],
discordChannel
);
return
;
}));
}).
then
(()
=>
{
});
}
private
UpdateRoomEntry
(
entry
:
Entry
,
discordChannel
:
Discord
.
TextChannel
):
Promise
<
null
>
{
const
intent
=
this
.
bridge
.
getIntent
();
const
roomStore
=
this
.
bridge
.
getRoomStore
();
const
roomId
=
entry
.
matrix
.
getId
();
return
new
Promise
(()
=>
{
const
name
=
`[Discord]
${
discordChannel
.
guild
.
name
}
#
${
discordChannel
.
name
}
`
;
const
name
=
`[Discord]
${
discordChannel
.
guild
.
name
}
#
${
discordChannel
.
name
}
`
;
if
(
entry
.
remote
.
get
(
"
discord_name
"
)
!==
name
)
{
if
(
entry
.
remote
.
get
(
"
update_name
"
)
&&
entry
.
remote
.
get
(
"
discord_name
"
)
!==
name
)
{
return
intent
.
setRoomName
(
roomId
,
name
).
then
(()
=>
{
return
intent
.
setRoomName
(
roomId
,
name
).
then
(()
=>
{
log
.
info
(
"
DiscordBot
"
,
`Updated name for
${
roomId
}
`
);
entry
.
remote
.
set
(
"
discord_name
"
,
name
);
entry
.
remote
.
set
(
"
discord_name
"
,
name
);
return
roomStore
.
upsertEntry
(
entry
);
return
roomStore
.
upsertEntry
(
entry
);
});
});
}
}
}).
then
(()
=>
{
}).
then
(()
=>
{
if
(
entry
.
remote
.
get
(
"
discord_topic
"
)
!==
discordChannel
.
topic
)
{
if
(
entry
.
remote
.
get
(
"
update_topic
"
)
&&
entry
.
remote
.
get
(
"
discord_topic
"
)
!==
discordChannel
.
topic
)
{
return
intent
.
setRoomTopic
(
roomId
,
discordChannel
.
topic
).
then
(()
=>
{
return
intent
.
setRoomTopic
(
roomId
,
discordChannel
.
topic
).
then
(()
=>
{
entry
.
remote
.
set
(
"
discord_topic
"
,
discordChannel
.
topic
);
entry
.
remote
.
set
(
"
discord_topic
"
,
discordChannel
.
topic
);
log
.
info
(
"
DiscordBot
"
,
`Updated topic for
${
roomId
}
`
);
return
roomStore
.
upsertEntry
(
entry
);
return
roomStore
.
upsertEntry
(
entry
);
});
});
}
}
...
@@ -292,9 +300,11 @@ export class DiscordBot {
...
@@ -292,9 +300,11 @@ export class DiscordBot {
}
}
private
OnTyping
(
channel
:
Discord
.
Channel
,
user
:
Discord
.
User
,
isTyping
:
boolean
)
{
private
OnTyping
(
channel
:
Discord
.
Channel
,
user
:
Discord
.
User
,
isTyping
:
boolean
)
{
return
this
.
GetRoomIdFromChannel
(
channel
).
then
((
room
)
=>
{
return
this
.
GetRoomId
s
FromChannel
(
channel
).
then
((
room
s
)
=>
{
const
intent
=
this
.
bridge
.
getIntentFromLocalpart
(
`_discord_
${
user
.
id
}
`
);
const
intent
=
this
.
bridge
.
getIntentFromLocalpart
(
`_discord_
${
user
.
id
}
`
);
return
intent
.
sendTyping
(
room
,
isTyping
);
return
Promise
.
all
(
rooms
.
map
((
room
)
=>
{
return
intent
.
sendTyping
(
room
,
isTyping
);
}));
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
log
.
verbose
(
"
DiscordBot
"
,
"
Failed to send typing indicator.
"
,
err
);
log
.
verbose
(
"
DiscordBot
"
,
"
Failed to send typing indicator.
"
,
err
);
});
});
...
@@ -335,8 +345,8 @@ export class DiscordBot {
...
@@ -335,8 +345,8 @@ export class DiscordBot {
return
;
// Skip *our* messages
return
;
// Skip *our* messages
}
}
this
.
UpdateUser
(
msg
.
author
).
then
(()
=>
{
this
.
UpdateUser
(
msg
.
author
).
then
(()
=>
{
return
this
.
GetRoomIdFromChannel
(
msg
.
channel
);
return
this
.
GetRoomId
s
FromChannel
(
msg
.
channel
);
}).
then
((
room
)
=>
{
}).
then
((
room
s
)
=>
{
const
intent
=
this
.
bridge
.
getIntentFromLocalpart
(
`_discord_
${
msg
.
author
.
id
}
`
);
const
intent
=
this
.
bridge
.
getIntentFromLocalpart
(
`_discord_
${
msg
.
author
.
id
}
`
);
// Check Attachements
// Check Attachements
msg
.
attachments
.
forEach
((
attachment
)
=>
{
msg
.
attachments
.
forEach
((
attachment
)
=>
{
...
@@ -353,22 +363,27 @@ export class DiscordBot {
...
@@ -353,22 +363,27 @@ export class DiscordBot {
info
.
w
=
attachment
.
width
;
info
.
w
=
attachment
.
width
;
info
.
h
=
attachment
.
height
;
info
.
h
=
attachment
.
height
;
}
}
intent
.
sendMessage
(
room
,
{
rooms
.
forEach
((
room
)
=>
{
body
:
attachment
.
filename
,
intent
.
sendMessage
(
room
,
{
info
,
body
:
attachment
.
filename
,
msgtype
,
info
,
url
:
content
.
mxc_url
,
msgtype
,
url
:
content
.
mxc_url
,
});
});
});
});
});
});
});
if
(
msg
.
content
!==
null
&&
msg
.
content
!==
""
)
{
if
(
msg
.
content
!==
null
&&
msg
.
content
!==
""
)
{
// Replace mentions.
// Replace mentions.
let
content
=
this
.
FormatDiscordMessage
(
msg
);
let
content
=
this
.
FormatDiscordMessage
(
msg
);
intent
.
sendMessage
(
room
,
{
const
fBody
=
marked
(
content
);
body
:
content
,
rooms
.
forEach
((
room
)
=>
{
msgtype
:
"
m.text
"
,
intent
.
sendMessage
(
room
,
{
formatted_body
:
marked
(
content
),
body
:
content
,
format
:
"
org.matrix.custom.html
"
,
msgtype
:
"
m.text
"
,
formatted_body
:
fBody
,
format
:
"
org.matrix.custom.html
"
,
});
});
});
}
}
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/dbschema/dbschema.ts
+
1
−
1
Voir le fichier @
45a7841b
import
{
DiscordStore
}
from
"
../store
"
;
import
{
DiscordStore
}
from
"
../store
"
;
export
interface
IDbSchema
{
export
interface
IDbSchema
{
description
:
string
,
description
:
string
;
run
(
store
:
DiscordStore
):
Promise
<
null
>
;
run
(
store
:
DiscordStore
):
Promise
<
null
>
;
}
}
Ce diff est replié.
Cliquez pour l'agrandir.
src/matrixroomhandler.ts
+
2
−
0
Voir le fichier @
45a7841b
...
@@ -145,6 +145,8 @@ export class MatrixRoomHandler {
...
@@ -145,6 +145,8 @@ export class MatrixRoomHandler {
remote
.
set
(
"
discord_type
"
,
"
text
"
);
remote
.
set
(
"
discord_type
"
,
"
text
"
);
remote
.
set
(
"
discord_guild
"
,
channel
.
guild
.
id
);
remote
.
set
(
"
discord_guild
"
,
channel
.
guild
.
id
);
remote
.
set
(
"
discord_channel
"
,
channel
.
id
);
remote
.
set
(
"
discord_channel
"
,
channel
.
id
);
remote
.
set
(
"
update_name
"
,
true
);
remote
.
set
(
"
update_topic
"
,
true
);
const
gname
=
channel
.
guild
.
name
.
replace
(
"
"
,
"
-
"
);
const
gname
=
channel
.
guild
.
name
.
replace
(
"
"
,
"
-
"
);
const
cname
=
channel
.
name
.
replace
(
"
"
,
"
-
"
);
const
cname
=
channel
.
name
.
replace
(
"
"
,
"
-
"
);
...
...
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