npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

discord-channel.db

v0.0.1

Published

Database in discord channels?

Downloads

6

Readme

discord-channel.db

Important Message Before Use

  • This package doesn't care about ratelimits of the discord api so use at your own risks 😁
  • This package can be extremely slow fetching values
  • Also since the values are stored in embeds, there exists "character limits" which would be 4000 * 10 = 40,000 (4000 = max characters per embed & 10 = max number of embeds per message)
  • This package do not have well readme page so sort the things sort your own 😉
  • Any Bugs or Improvement in the package? Message leziuwu on discord.

Installation

Download the package from npm,

$ npm i discord-channel.db

After installing your can import the database using,

import { Database } from "discord-channel.db";
//or
const { Database } = require("discord-channel.db");

Initialising Database

const client = new Client({
  ... // your client options
});

/* Default Database Options Shown */
const database = new Database(client, {
  guilds: ["1234"],
  deleteNonDBChannels: false,
  size: 10,
  cacheEvery: 30_000
});

client.on('ready', async () => {
  await database.connect(); 
})

Database Options.

| Property | Type | Description | Required | | :---: | :---: | :---: | :---: | | guilds | string[] | Array of guilds which should be considered as database guilds | true | | deleteNonDBChannels | boolean? | Permission for database to delete all the non db channels from the guild (dangerous) | false (default = false) | | size | number? | Number of database channels per guild (range: 1 to 25) | false (default = 10) | | cacheEvery | number? | Interval to create cache every "x" milliseconds (range: 10s to 1hr) | false (default = 30,000) |

Database Properties

  • database.options: [Required<IDatabaseOptions>]
    • Returns the database options.
console.log(database.options); // {...}
  • database.isConnected: [boolean]
    • Returns true if database has been connected.
console.log(database.isConnected); // true or false
  • database.client: [Client]
    • The client which initialise the database
console.log(database.client); // Client {...}
  • database.guilds: [Guild[]]
    • Array of database guilds
console.log(database.guilds); // [Guild, Guild, ...]
  • database.cache: [Collection<string, KeyValue>]
    • Collection of keys and its values.
console.log(database.cache); // Collection {...}
  • database.size: [number]
    • Same as database.cache.size
console.log(database.size); // some Integer 

Database Methods

  • database.connect
/**
 * Connects the database
 */
database.connect(): Promise<boolean>;
  • database.channels
/**
 * List of database channels
 */
database.channels(): Promise<TextChannel[]>;

Database Functions

  • database.wipe
/**
 * Wipes the database.
 */
database.wipe(): Promise<boolean>;
  • database.set
/**
 * Sets a value to the database
 * @param key {string} Key to store the value as.
 * @param value {any} Value to store.
 */
database.set(key: string, value: any): Promise<KeyValue | null>;

/* Example */
await database.set("key", "some value");
  • database.get
/**
 * Gets an value from database
 * @param key {string} Key to get the value of
 */
database.get(key: string): {
  key: string;
  value: any;
  type: string;
  createdTimestamp: number;
  editedTimestamp: number;
  _id: string;
} | null;

/* Example */
database.get("key");
  • database.all
/**
 * Returns all values from database
 * @param type {string?} Type of value to return
 */
database.all(type?: string): Promise<{
  key: string;
  value: any;
  type: string;
  createdTimestamp: number;
  editedTimestamp: number;
  _id: string;
}[]>;

/* Example */
await database.all(); //or
await database.all("string");
  • database.delete
/**
 * Deletes a value from database
 * @param key {string} Key to delete
 */
database.delete(key: string): Promise<boolean | null>;

/* Example */
await database.delete("key");
  • database.bulkSet
/**
 * Sets multiple values at one call.
 * @param ...data {[string, any][]} Key and value
 */
database.bulkSet(...data: [string, any][]): Promise<(KeyValue | null)[] | null>;

/* Example */
await database.bulkSet(
  ["key1", "value1"], 
  ["key2", "value2"]
);
  • database.bulkDelete
/**
 * Deletes multiple values at one call.
 * @param ...keys {string[]} Keys to delete
 */
database.bulkDelete(...keys: string[]): Promise<this | null>;

/* Example */
await database.bulkDelete("key1", "key2");
  • database.find
/**
 * Finds the query in the database
 * @param query {string | RegExp | ((key: string, kv: KeyValue) => boolean)} Query to search
 * @param type {string?} Type to search
 */
database.find(query: string | RegExp | ((key: string, kv: KeyValue) => boolean), type?: string): Promise<{
  key: string;
  value: any;
  type: string;
  createdTimestamp: number;
  editedTimestamp: number;
  _id: string;
}[]>;

/* Example */
await database.find("some key") //or
await database.find(/some [Kk]ey/) //or
await database.find((key: string) => 
  key.includes("some key")
);
  • database.ping
/**
 * Gets ping
 * @param showCachePing {boolean?} Also returns the time took to cache (if true then it forces cache)
 */
database.ping(showCachePing?: boolean): Promise<{
  write: number;
  edit: number;
  delete: number;
  cache: number;
  total: number;
}>;