Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 11a5662bcf702215df8002274d2caaac34a4f1d4
  • main par défaut protégée
  • sting
3 résultats

all.lua

Blame
  • util.ts 14,66 Kio
    /*
    Copyright 2018, 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 * as http from "http";
    import * as https from "https";
    import { Buffer } from "buffer";
    import { Permissions } from "better-discord.js";
    import { DiscordBridgeConfig } from "./config";
    import { IMatrixEvent } from "./matrixtypes";
    
    const HTTP_OK = 200;
    
    import { Log } from "./log";
    import { Intent, MatrixClient } from "matrix-bot-sdk";
    const log = new Log("Util");
    
    type PERMISSIONTYPES = any | any[]; // tslint:disable-line no-any
    
    export interface ICommandAction {
        description?: string;
        help?: string;
        params: string[];
        permission?: PERMISSIONTYPES;
        run(params: any): Promise<any>; // tslint:disable-line no-any
    }
    
    export interface ICommandActions {
        [index: string]: ICommandAction;
    }
    
    export interface ICommandParameter {
        description?: string;
        get?(param: string): Promise<any>; // tslint:disable-line no-any
    }
    
    export interface ICommandParameters {
        [index: string]: ICommandParameter;
    }
    
    export type CommandPermissonCheck = (permission: PERMISSIONTYPES) => Promise<boolean | string>;
    
    export interface IDownloadedFile {
        buffer: Buffer;
        mimeType?: string;
    }
    
    export interface IPatternMap {
        [index: string]: string;
    }
    
    export class Util {
        /**
         * downloadFile - This function will take a URL and store the resulting data into
         * a buffer.
         */
        public static async DownloadFile(url: string): Promise<IDownloadedFile> {
            return new Promise((resolve, reject) => {