Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 158ddb8a23ecb99ac0694b8f3527178f7e0b76b8
  • develop par défaut protégée
  • implement-discord-markdown-update
  • matrix-attachments-order-fix
  • fix-oversized-file-transfer
  • matrix-attachment-order-fix
  • matrix-answer-modified-fix
  • cherry-pick-moise
8 résultats

toolshelper.ts

Blame
  • Bifurcation depuis ARISE / matrix-appservice-discord
    Le projet source a une visibilité limitée.
    toolshelper.ts 1,39 Kio
    import { DiscordBridgeConfig } from "../src/config";
    import { Appservice } from "matrix-bot-sdk";
    import { DiscordStore } from "../src/store";
    import * as yaml from "js-yaml";
    import * as fs from "fs";
    
    export class ToolsHelper {
        public static getToolDependencies(
            configFile: string, regFile: string = "./discord-registration.yaml", needsStore: boolean = true): {
            store: DiscordStore|null,
            appservice: Appservice,
            config: DiscordBridgeConfig,
        } {
            const registration = yaml.safeLoad(fs.readFileSync(regFile, "utf8"));
            const config: DiscordBridgeConfig = Object.assign(
                new DiscordBridgeConfig(), yaml.safeLoad(fs.readFileSync(configFile, "utf8")));
            config.applyEnvironmentOverrides(process.env);
            if (registration === null) {
                throw Error("Failed to parse registration file");
            }
    
            const appservice = new Appservice({
                bindAddress: "notathing",
                homeserverName: config.bridge.domain,
                homeserverUrl: config.bridge.homeserverUrl,
                port: 0,
                // We assume the registration is well formed
                registration: registration as any,
            });
    
            const store = needsStore ? new DiscordStore(config.database ? config.database.filename : "discord.db") : null;
            return {
                appservice,
                config,
                store,
            };
        }
    }