Skip to content

Skillz4Killz/gapi

Repository files navigation

gapi / gupi

CI npm Guilded

A TypeScript NodeJS API Wrapper for Guilded.gg API.

image

Currently unstable and in active dev. Use with caution.

The name is gapi but silly google took that name so on npm we use gupi

Design Goals

  • Amazing Scalability!
  • Great developer experience!
  • Extremely flexible/dynamic!

Features

  • Initial Connection
    • Handle closes/Reconnection
  • Advanced RAM control!
    • Add custom props
    • Remove undesired props to save RAM
    • Limit the max amount of items in a collection.
  • Basic Cache control
  • Clean and powerful events system
    • Event listeners that are ran when an event occurs.
    • Useful events available to help debug!
  • Clean and powerful tasks system.
    • Runs a function at a certain interval. Useful for things like unmute and updating bot lists etc.
    • Can be used for cache sweeping to keep your cache optimized for exactly what you want.
  • Clean and powerful monitors system.
    • Runs a function on every message sent. Useful for stuff like auto-moderation or tags.
    • Easily ignore bots, users, edits, dms.
    • Powerful permission checks.
  • Clean and powerful inhibitors system
    • Stops a command from running if a requirement fails.
    • Easily add custom inhibitors!
  • Clean and powerful commands system
    • Powerful argument handling including validating, parsing and modifications.
    • Easily create custom arguments for your specific needs.
    • Command aliases.
    • Cooldowns and allowed uses before cooldown triggers.
    • Argument prompting!
    • Author and bot permission checks in server AND in channel!
  • Clean and powerful languages system.
    • Built in multi-lingual support.
    • Uses i18next, one of the best localization tools available.
    • Supports nested folders to keep cleaner translation files
  • GH Actions
    • Linter
    • Prettier
    • TSC
  • Event Handlers
  • 100% API coverage
  • Custom(Redis) cache support
  • Step by step guide
  • GH Actions: Deploy on release
  • Readme image/logo??
  • Proxy WS support (Pending until sharding is implemented in Guilded)
  • Proxy REST support (Pending until Rate Limits are better implemented in Guilded)

Usage

Beginner/Basic

import { Client } from 'gupi';

new Client({ email: 'emailhere', password: 'passwordhere' })
  .on('ready', () => console.log('Successfully connected to gateway'))
  .on('messageCreate', message => {
    if (message.content === '!ping') {
      message.send(`Ping MS: ${Date.now() - message.timestamp}ms`);
    }
  })
  .on('unknown', console.log)
  .connect();

BotClient (Full Command Framework)

// index.ts
import { BotClient } from 'gupi';
import configs from './configs';

// Start it up!
const client = new BotClient(configs).on('ready', () => console.log('Successfully connected to gateway')).connect();

// src/commands/avatar.ts
import { Command, CommandArgument, Message, User, Embed } from 'gupi';

export default class extends Command {
  name = 'avatar';
  aliases = ['pfp'];
  description = '🖼️ View the avatar image for a user or the server.';
  arguments = [
    { name: 'server', type: 'string', literals: ['server'], required: false },
    { name: 'user', type: 'user', required: false },
  ] as CommandArgument[];

  async execute(message: Message, args: { user?: User; server?: 'server' }) {
    // BY DEFAULT WE USE THE USERS OWN URL
    let url = message.author.dynamicAvatarURL({ type: 'Large' });
    // IF THE USER WANTED THE SERVER AVATAR USE IT
    if (args.server && message.team) url = message.team.dynamicAvatarURL({ type: 'Large' });
    // IF A USER WAS REQUESTED, THEN WE USE THAT
    if (args.user) url = args.user.dynamicAvatarURL({ type: 'Large' });

    return message.send(
      new Embed()
        .setAuthor(message.author)
        .setDescription(`[${message.translate('commands/avatar:DOWNLOAD_LINK')}](${url})`)
        .setImage(url),
    );
  }
}

image

Advanced Customizations

Everything below this is to showcase examples of advanced features! They are intentionally written in a way that is confusing to a beginner developer, as it is not meant for you. This is an extreme edge case scenario for bots that scale really big!

// Cache Control!
// Set to 0 to disable caching. Apply to any desired Collection.
client.users.maxSize = 1000;

client.connect();