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
0f4e4ab1
Valider
0f4e4ab1
rédigé
27 janv. 2019
par
Will Hunt
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Fix createMatrixRoom for new roomstore
parent
5bc174d3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
src/discordas.ts
+1
-1
1 ajout, 1 suppression
src/discordas.ts
src/matrixroomhandler.ts
+42
-19
42 ajouts, 19 suppressions
src/matrixroomhandler.ts
avec
43 ajouts
et
20 suppressions
src/discordas.ts
+
1
−
1
Voir le fichier @
0f4e4ab1
...
...
@@ -122,7 +122,6 @@ async function run(port: number, fileConfig: DiscordBridgeConfig) {
userStore
:
config
.
database
.
userStorePath
,
// To avoid out of order message sending.
});
roomhandler
.
setBridge
(
bridge
);
discordbot
.
setBridge
(
bridge
);
discordbot
.
setRoomHandler
(
roomhandler
);
log
.
info
(
"
Initing bridge.
"
);
...
...
@@ -134,6 +133,7 @@ async function run(port: number, fileConfig: DiscordBridgeConfig) {
await
discordstore
.
init
();
log
.
info
(
"
Initing bot.
"
);
provisioner
.
setStore
(
discordstore
.
roomStore
);
roomhandler
.
setBridge
(
bridge
,
discordstore
.
roomStore
);
await
discordbot
.
run
();
log
.
info
(
"
Discordbot started successfully.
"
);
}
catch
(
err
)
{
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/matrixroomhandler.ts
+
42
−
19
Voir le fichier @
0f4e4ab1
...
...
@@ -35,6 +35,7 @@ import { Provisioner } from "./provisioner";
import
{
Log
}
from
"
./log
"
;
const
log
=
new
Log
(
"
MatrixRoomHandler
"
);
import
{
IMatrixEvent
}
from
"
./matrixtypes
"
;
import
{
DbRoomStore
,
MatrixStoreRoom
,
RemoteStoreRoom
}
from
"
./db/roomstore
"
;
const
ICON_URL
=
"
https://matrix.org/_matrix/media/r0/download/matrix.org/mlxoESwIsTbJrfXyAAogrNxA
"
;
/* tslint:disable:no-magic-numbers */
...
...
@@ -58,14 +59,16 @@ const JOIN_ROOM_SCHEDULE = [
/* tslint:enable:no-magic-numbers */
export
class
MatrixRoomHandler
{
private
config
:
DiscordBridgeConfig
;
private
bridge
:
Bridge
;
private
discord
:
DiscordBot
;
private
botUserId
:
string
;
private
roomStore
:
DbRoomStore
;
private
botJoinedRooms
:
Set
<
string
>
;
// roomids
private
botJoinedRoomsCacheUpdatedAt
=
0
;
constructor
(
discord
:
DiscordBot
,
config
:
DiscordBridgeConfig
,
botUserId
:
string
,
private
provisioner
:
Provisioner
)
{
constructor
(
private
discord
:
DiscordBot
,
private
config
:
DiscordBridgeConfig
,
private
botUserId
:
string
,
private
provisioner
:
Provisioner
,
)
{
this
.
discord
=
discord
;
this
.
config
=
config
;
this
.
botUserId
=
botUserId
;
...
...
@@ -83,14 +86,28 @@ export class MatrixRoomHandler {
};
}
public
setBridge
(
bridge
:
Bridge
)
{
public
setBridge
(
bridge
:
Bridge
,
roomStore
:
DbRoomStore
)
{
this
.
bridge
=
bridge
;
this
.
roomStore
=
roomStore
;
}
public
async
OnAliasQueried
(
alias
:
string
,
roomId
:
string
)
{
log
.
verbose
(
`Got OnAliasQueried for
${
alias
}
${
roomId
}
`
);
let
channel
:
Discord
.
GuildChannel
;
try
{
// We previously stored the room as an alias.
const
entry
=
(
await
this
.
roomStore
.
getEntriesByMatrixId
(
alias
))[
0
];
if
(
!
entry
)
{
throw
new
Error
(
"
Entry was not found
"
);
}
// Remove the old entry
await
this
.
roomStore
.
removeEntriesByMatrixRoomId
(
entry
.
matrix
!
.
roomId
,
);
await
this
.
roomStore
.
linkRooms
(
new
MatrixStoreRoom
(
roomId
),
entry
.
remote
!
,
);
channel
=
await
this
.
discord
.
GetChannelFromRoomId
(
roomId
)
as
Discord
.
GuildChannel
;
}
catch
(
err
)
{
log
.
error
(
`Cannot find discord channel for
${
alias
}
${
roomId
}
`
,
err
);
...
...
@@ -130,7 +147,7 @@ export class MatrixRoomHandler {
await
Promise
.
all
(
promiseList
);
}
public
async
OnEvent
(
request
,
context
):
Promise
<
void
>
{
public
async
OnEvent
(
request
,
context
:
BridgeContext
):
Promise
<
void
>
{
const
event
=
request
.
getData
()
as
IMatrixEvent
;
if
(
event
.
unsigned
.
age
>
AGE_LIMIT
)
{
log
.
warn
(
`Skipping event due to age
${
event
.
unsigned
.
age
}
>
${
AGE_LIMIT
}
`
);
...
...
@@ -210,7 +227,7 @@ export class MatrixRoomHandler {
);
await
sendPromise
;
await
intent
.
leave
(
roomId
);
await
this
.
bridge
.
getR
oomStore
()
.
removeEntriesByMatrixRoomId
(
roomId
);
await
this
.
r
oomStore
.
removeEntriesByMatrixRoomId
(
roomId
);
}
public
async
HandleInvite
(
event
:
IMatrixEvent
)
{
...
...
@@ -405,7 +422,7 @@ export class MatrixRoomHandler {
try
{
const
result
=
await
this
.
discord
.
LookupRoom
(
srvChanPair
[
0
],
srvChanPair
[
1
]);
log
.
info
(
"
Creating #
"
,
aliasLocalpart
);
return
this
.
createMatrixRoom
(
result
.
channel
,
aliasLocalpart
);
return
this
.
createMatrixRoom
(
result
.
channel
,
alias
,
aliasLocalpart
);
}
catch
(
err
)
{
log
.
error
(
`Couldn't find discord room '
${
aliasLocalpart
}
'.`
,
err
);
}
...
...
@@ -622,14 +639,16 @@ export class MatrixRoomHandler {
}
}
private
createMatrixRoom
(
channel
:
Discord
.
TextChannel
,
alias
:
string
):
ProvisionedRoom
{
const
remote
=
new
RemoteRoom
(
`discord_
${
channel
.
guild
.
id
}
_
${
channel
.
id
}
`
);
remote
.
set
(
"
discord_type
"
,
"
text
"
);
remote
.
set
(
"
discord_guild
"
,
channel
.
guild
.
id
);
remote
.
set
(
"
discord_channel
"
,
channel
.
id
);
remote
.
set
(
"
update_name
"
,
true
);
remote
.
set
(
"
update_topic
"
,
true
);
remote
.
set
(
"
update_icon
"
,
true
);
private
async
createMatrixRoom
(
channel
:
Discord
.
TextChannel
,
alias
:
string
,
aliasLocalpart
:
string
):
ProvisionedRoom
{
const
remote
=
new
RemoteStoreRoom
(
`discord_
${
channel
.
guild
.
id
}
_
${
channel
.
id
}
`
,
{
discord_channel
:
channel
.
id
,
discord_guild
:
channel
.
guild
.
id
,
discord_type
:
"
text
"
,
update_icon
:
1
,
update_name
:
1
,
update_topic
:
1
,
});
const
creationOpts
=
{
initial_state
:
[
{
...
...
@@ -640,12 +659,16 @@ export class MatrixRoomHandler {
type
:
"
m.room.join_rules
"
,
},
],
room_alias_name
:
alias
,
room_alias_name
:
alias
Localpart
,
visibility
:
this
.
config
.
room
.
defaultVisibility
,
};
// We need to tempoarily store this until we know the room_id.
await
this
.
roomStore
.
linkRooms
(
new
MatrixStoreRoom
(
alias
),
remote
,
);
return
{
creationOpts
,
remote
,
}
as
ProvisionedRoom
;
}
...
...
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