Sélectionner une révision Git
Bifurcation depuis
ARISE / matrix-appservice-discord
Le projet source a une visibilité limitée.
-
Christian Paul a rédigéChristian Paul a rédigé
discordas.ts 7,47 Kio
/*
Copyright 2017 - 2019 matrix-appservice-discord
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { Appservice, IAppserviceRegistration, LogService } from "matrix-bot-sdk";
import * as yaml from "js-yaml";
import * as fs from "fs";
import { DiscordBridgeConfig } from "./config";
import { DiscordBot } from "./bot";
import { DiscordStore } from "./store";
import { Log } from "./log";
import "source-map-support/register";
import * as cliArgs from "command-line-args";
import * as usage from "command-line-usage";
import * as uuid from "uuid/v4";
import { IMatrixEvent } from "./matrixtypes";
import { MetricPeg, PrometheusBridgeMetrics } from "./metrics";
const log = new Log("DiscordAS");
const commandOptions = [
{ name: "config", alias: "c", type: String },
{ name: "url", alias: "u", type: String },
{ name: "port", alias: "p", type: Number },
{ name: "file", alias: "f", type: String },
{ name: "generate-registration", alias: "r", type: Boolean },
{ name: "help", alias: "h", type: Boolean },
];
function generateRegistration(opts, registrationPath) {
if (!opts.url) {
throw Error("'url' not given in command line opts, cannot generate registration file");
}
const reg = {
as_token: uuid(),
hs_token: uuid(),
id: "discord-bridge",
namespaces: {
aliases: [
{
exclusive: true,
regex: "#_discord_.*",
},
],
rooms: [ ],
users: [
{
exclusive: true,
regex: "@_discord_.*",
},
],
},
protocols: ["discord"],
rate_limited: false,
sender_localpart: "_discord_bot",
url: opts.url,
} as IAppserviceRegistration;
fs.writeFileSync(registrationPath, yaml.safeDump(reg));
}