Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
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
ARISE
matrix-appservice-discord
Validations
09a36313
Valider
09a36313
rédigé
Il y a 3 ans
par
Tadeusz Sośnierz
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Notify a configurable bridge admin if the Discord token is invalid on startup
parent
732be164
Branches
Branches contenant la validation
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
config/config.sample.yaml
+3
-1
3 ajouts, 1 suppression
config/config.sample.yaml
src/config.ts
+1
-0
1 ajout, 0 suppression
src/config.ts
src/discordas.ts
+39
-4
39 ajouts, 4 suppressions
src/discordas.ts
avec
43 ajouts
et
5 suppressions
config/config.sample.yaml
+
3
−
1
Voir le fichier @
09a36313
...
@@ -38,6 +38,8 @@ bridge:
...
@@ -38,6 +38,8 @@ bridge:
disableInviteNotifications
:
false
disableInviteNotifications
:
false
# Auto-determine the language of code blocks (this can be CPU-intensive)
# Auto-determine the language of code blocks (this can be CPU-intensive)
determineCodeLanguage
:
false
determineCodeLanguage
:
false
# MXID of an admin user that will be PMd if the bridge experiences problems. Optional
adminMxid
:
'
@admin:localhost'
# Authentication configuration for the discord bot.
# Authentication configuration for the discord bot.
auth
:
auth
:
# This MUST be a string (wrapped in quotes)
# This MUST be a string (wrapped in quotes)
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/config.ts
+
1
−
0
Voir le fichier @
09a36313
...
@@ -100,6 +100,7 @@ class DiscordBridgeConfigBridge {
...
@@ -100,6 +100,7 @@ class DiscordBridgeConfigBridge {
public
determineCodeLanguage
:
boolean
=
false
;
public
determineCodeLanguage
:
boolean
=
false
;
public
activityTracker
:
UserActivityTrackerConfig
=
UserActivityTrackerConfig
.
DEFAULT
;
public
activityTracker
:
UserActivityTrackerConfig
=
UserActivityTrackerConfig
.
DEFAULT
;
public
userLimit
:
number
|
null
=
null
;
public
userLimit
:
number
|
null
=
null
;
public
adminMxid
:
string
|
null
=
null
;
}
}
export
class
DiscordBridgeConfigDatabase
{
export
class
DiscordBridgeConfigDatabase
{
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/discordas.ts
+
39
−
4
Voir le fichier @
09a36313
...
@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
import
{
Appservice
,
IAppserviceRegistration
,
LogService
}
from
"
matrix-bot-sdk
"
;
import
{
Appservice
,
IAppserviceRegistration
,
LogService
,
MatrixClient
}
from
"
matrix-bot-sdk
"
;
import
*
as
yaml
from
"
js-yaml
"
;
import
*
as
yaml
from
"
js-yaml
"
;
import
*
as
fs
from
"
fs
"
;
import
*
as
fs
from
"
fs
"
;
import
{
DiscordBridgeConfig
}
from
"
./config
"
;
import
{
DiscordBridgeConfig
}
from
"
./config
"
;
...
@@ -30,6 +30,8 @@ import { Response } from "express";
...
@@ -30,6 +30,8 @@ import { Response } from "express";
const
log
=
new
Log
(
"
DiscordAS
"
);
const
log
=
new
Log
(
"
DiscordAS
"
);
const
ADMIN_ROOMS_KEY
=
'
uk.half-shot.discord.admin-rooms
'
;
const
commandOptions
=
[
const
commandOptions
=
[
{
name
:
"
config
"
,
alias
:
"
c
"
,
type
:
String
},
{
name
:
"
config
"
,
alias
:
"
c
"
,
type
:
String
},
{
name
:
"
url
"
,
alias
:
"
u
"
,
type
:
String
},
{
name
:
"
url
"
,
alias
:
"
u
"
,
type
:
String
},
...
@@ -215,7 +217,7 @@ async function run(): Promise<void> {
...
@@ -215,7 +217,7 @@ async function run(): Promise<void> {
roomhandler
.
bindThirdparty
();
roomhandler
.
bindThirdparty
();
try
{
try
{
await
startDiscordBot
(
discordbot
);
await
startDiscordBot
(
discordbot
,
appservice
.
botClient
,
config
.
bridge
.
adminMxid
);
log
.
info
(
"
Discordbot started successfully
"
);
log
.
info
(
"
Discordbot started successfully
"
);
}
catch
(
err
)
{
}
catch
(
err
)
{
log
.
error
(
err
);
log
.
error
(
err
);
...
@@ -228,16 +230,49 @@ async function run(): Promise<void> {
...
@@ -228,16 +230,49 @@ async function run(): Promise<void> {
}
}
async
function
startDiscordBot
(
discordbot
:
DiscordBot
,
falloffSeconds
=
5
)
{
interface
AdminRooms
{
[
mxid
:
string
]:
string
;
}
async
function
notifyBridgeAdmin
(
client
:
MatrixClient
,
adminMxid
:
string
,
message
:
string
)
{
log
.
verbose
(
`Looking up admin room for
${
adminMxid
}
`
);
let
adminRooms
=
await
client
.
getAccountData
<
AdminRooms
>
(
ADMIN_ROOMS_KEY
).
catch
(()
=>
null
)
||
{};
if
(
!
adminRooms
[
adminMxid
])
{
log
.
verbose
(
`Creating an admin room for
${
adminMxid
}
`
);
adminRooms
[
adminMxid
]
=
await
client
.
createRoom
();
await
client
.
inviteUser
(
adminMxid
,
adminRooms
[
adminMxid
]);
await
client
.
setAccountData
(
ADMIN_ROOMS_KEY
,
adminRooms
);
}
await
client
.
sendText
(
adminRooms
[
adminMxid
],
message
)
}
let
adminNotified
=
false
;
async
function
startDiscordBot
(
discordbot
:
DiscordBot
,
client
:
MatrixClient
,
adminMxid
:
string
|
null
,
falloffSeconds
=
5
)
{
try
{
try
{
await
discordbot
.
init
();
await
discordbot
.
init
();
await
discordbot
.
run
();
await
discordbot
.
run
();
}
catch
(
err
)
{
}
catch
(
err
)
{
if
(
err
.
code
===
'
TOKEN_INVALID
'
&&
adminMxid
&&
!
adminNotified
)
{
await
notifyBridgeAdmin
(
client
,
adminMxid
,
`Your Discord bot token seems to be invalid, and the bridge cannot function. Please update it in your bridge settings and restart the bridge`
);
adminNotified
=
true
;
}
// no more than 5 minutes
// no more than 5 minutes
const
newFalloffSeconds
=
Math
.
min
(
falloffSeconds
*
2
,
5
*
60
);
const
newFalloffSeconds
=
Math
.
min
(
falloffSeconds
*
2
,
5
*
60
);
log
.
error
(
`Failed do start Discordbot:
${
err
.
code
}
. Will try again in
${
newFalloffSeconds
}
seconds`
);
log
.
error
(
`Failed do start Discordbot:
${
err
.
code
}
. Will try again in
${
newFalloffSeconds
}
seconds`
);
await
new
Promise
((
r
,
_
)
=>
setTimeout
(
r
,
newFalloffSeconds
*
1000
));
await
new
Promise
((
r
,
_
)
=>
setTimeout
(
r
,
newFalloffSeconds
*
1000
));
return
startDiscordBot
(
discordbot
,
newFalloffSeconds
);
return
startDiscordBot
(
discordbot
,
client
,
adminMxid
,
newFalloffSeconds
);
}
if
(
adminMxid
&&
adminNotified
)
{
await
notifyBridgeAdmin
(
client
,
adminMxid
,
`The token situation is now resolved and the bridge is running correctly`
);
adminNotified
=
false
;
}
}
}
}
...
...
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