UNPKG

@amelix/phoenix.js

Version:

A feature-rich API wrapper for the critically acclaimed chatting app Phoenix.. or something.

79 lines (78 loc) 3.6 kB
import { Socket } from "socket.io-client"; import { AnyChannel } from "./Channel"; import ClientUser from "./ClientUser"; import EventEmitter from "./EventEmitter"; import Invite from "./Invite"; import Member from "./Member"; import Message from "./Message"; import PhoenixResponse from './PhoenixResponse'; import Server from "./Server"; import User, { AnyUser } from "./User"; export declare interface Client { on<U extends keyof ClientEvents>(event: U, callback: ClientEvents[U]): void; once<U extends keyof ClientEvents>(event: U, callback: ClientEvents[U]): void; emit<U extends keyof ClientEvents>(event: U, ...args: any[]): void; } interface ClientEvents { /** Emitted once the client has built all structures and initiated a connection with the server. */ 'ready': () => void; /** Emitted when a member joins a server. */ 'serverJoin': (member: Member) => void; /** Emitted when a server's name, owner, or icon is edited. */ 'serverEdit': (oldServer: Server, newServer: Server) => void; 'serverDelete': (server: Server) => void; 'channelCreate': (channel: AnyChannel) => void; /** Emitted when a channel's name or position is edited. */ 'channelEdit': (oldChannel: AnyChannel, newChannel: AnyChannel) => void; 'channelDelete': (channel: AnyChannel) => void; /** Emitted when a user starts typing in a channel. */ 'typingStart': (user: User, channel: AnyChannel) => void; /** Emitted when a user stops typing in a channel. */ 'typingStop': (user: User, channel: AnyChannel) => void; /** Emitted when a user's username or profile picture is edited. */ 'userEdit': (oldUser: User, newUser: User) => void; 'userDelete': (user: User) => void; 'inviteCreate': (invite: Invite) => void; /** Emitted when an invite's ID, max uses, allowed users or expiry date is edited. */ 'inviteEdit': (oldInvite: Invite, newInvite: Invite) => void; 'inviteDelete': (invite: Invite) => void; /** Emitted when a user sends a message to a channel. */ 'message': (message: Message) => void; /** Emitted when a message's content is edited. */ 'messageEdit': (oldMessage: Message, newMessage: Message) => void; 'messageDelete': (message: Message) => void; } export declare class Client extends EventEmitter { token: string; socket?: Socket; user: ClientUser; servers: Map<string, Server>; channels: Map<string, AnyChannel>; users: Map<string, AnyUser>; invites: Map<string, Invite>; constructor(token: string); private build; /** * Fully disconnect the client and delete the token. This terminates all authorised communiation with the Phoenix Server. * This is not available to bots. */ logout(): Promise<void>; private connect; /** Terminate the real time communication between this client and the server. */ disconnect(): void; /** * Create a Phoenix server. All Phoenix servers will have a general text channel made on their creation. * This is not available to bots. */ createServer(name: string): Promise<Server>; request<T = any>(method: string | undefined, path: string, headers?: { [k: string]: string; }, write?: any): Promise<PhoenixResponse<T>>; private fetchServer; private fetchChannel; /** Fetch a Phoenix user by ID. */ fetchUser(id: string): Promise<AnyUser>; /** Fetch a Phoenix invite by ID. */ fetchInvite(id: string): Promise<Invite | undefined>; } export {};