README Update, remove client from Cache Adapters, clean up test code
This commit is contained in:
		
							parent
							
								
									e40b7bd544
								
							
						
					
					
						commit
						4228cd8f52
					
				
					 4 changed files with 44 additions and 42 deletions
				
			
		
							
								
								
									
										39
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										39
									
								
								README.md
									
										
									
									
									
								
							|  | @ -1,10 +1,16 @@ | ||||||
| # discord-deno | # discord-deno | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
| 
 |  | ||||||
| [](https://github.com/RichardLitt/standard-readme) | [](https://github.com/RichardLitt/standard-readme) | ||||||
| 
 | 
 | ||||||
| **An easy to use Discord API Library for Deno** | **An easy to use Discord API Library for Deno.** | ||||||
|  | * Lightweight and easy to use. | ||||||
|  | * 100% Discord API Coverage. | ||||||
|  | * Customizable caching. | ||||||
|  |   * Built in support for Redis. | ||||||
|  |   * Write Custom Cache Adapters. | ||||||
|  | * Complete TypeScript support. | ||||||
|  | 
 | ||||||
|  | Note: Library is yet under development and not completely usable. You're still always welcome to use, but there may be breaking changes. | ||||||
| 
 | 
 | ||||||
| ## Table of Contents | ## Table of Contents | ||||||
| 
 | 
 | ||||||
|  | @ -15,25 +21,38 @@ | ||||||
| - [License](#license) | - [License](#license) | ||||||
| 
 | 
 | ||||||
| ## Usage | ## Usage | ||||||
|  | Right now, the package is not published anywhere, as its not completely usable. | ||||||
|  | You can import it from this Raw GitHub URL: https://raw.githubusercontent.com/discord-deno/discord.deno/main/mod.ts | ||||||
| 
 | 
 | ||||||
|  | For a quick example, run this: | ||||||
|  | ```bash | ||||||
|  | deno run --allow-net https://raw.githubusercontent.com/discord-deno/discord.deno/main/examples/ping.ts | ||||||
|  | ``` | ||||||
|  | And input your bot's token and Intents. | ||||||
|  | 
 | ||||||
|  | Here is a small example of how to use discord.deno, | ||||||
| ```ts | ```ts | ||||||
| import { Client } from 'https://deno.land/x/discord-deno/models/client.ts' | import { Client, Message, Intents } from 'https://raw.githubusercontent.com/discord-deno/discord.deno/main/mod.ts' | ||||||
| import { Message } from 'https://deno.land/x/discord-deno/structures/message.ts' |  | ||||||
| 
 | 
 | ||||||
| const bot = new Client() | const client = new Client() | ||||||
| 
 | 
 | ||||||
| bot.on('messageCreate', (msg: Message): void => { | client.on('ready', () => { | ||||||
|  |   console.log(`Ready! User: ${client.user?.tag}`) | ||||||
|  | }) | ||||||
|  | 
 | ||||||
|  | client.on('messageCreate', (msg: Message): void => { | ||||||
|   if (msg.content === '!ping') { |   if (msg.content === '!ping') { | ||||||
|     msg.channel.send(`Pong! ping: ${bot.ping}`) |     msg.channel.send(`Pong! WS Ping: ${client.ping}`) | ||||||
|   } |   } | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| bot.connect(TOKEN, [GatewayIntents.GUILD_MESSAGES]) | // Replace with your bot's token and intents (Intents.All, Intents.Presence, Intents.GuildMembers) | ||||||
|  | client.connect('super secret token comes here', Intents.All) | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| ## Docs | ## Docs | ||||||
| 
 | 
 | ||||||
| Not made yet | Not made yet. | ||||||
| 
 | 
 | ||||||
| ## Maintainer | ## Maintainer | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -7,7 +7,6 @@ import { | ||||||
| } from 'https://denopkg.com/keroxp/deno-redis/mod.ts' | } from 'https://denopkg.com/keroxp/deno-redis/mod.ts' | ||||||
| 
 | 
 | ||||||
| export interface ICacheAdapter { | export interface ICacheAdapter { | ||||||
|   client: Client |  | ||||||
|   get: (cacheName: string, key: string) => Promise<any> | any |   get: (cacheName: string, key: string) => Promise<any> | any | ||||||
|   set: (cacheName: string, key: string, value: any) => Promise<any> | any |   set: (cacheName: string, key: string, value: any) => Promise<any> | any | ||||||
|   delete: (cacheName: string, key: string) => Promise<boolean> | boolean |   delete: (cacheName: string, key: string) => Promise<boolean> | boolean | ||||||
|  | @ -16,15 +15,10 @@ export interface ICacheAdapter { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export class DefaultCacheAdapter implements ICacheAdapter { | export class DefaultCacheAdapter implements ICacheAdapter { | ||||||
|   client: Client |  | ||||||
|   data: { |   data: { | ||||||
|     [name: string]: Collection<string, any> |     [name: string]: Collection<string, any> | ||||||
|   } = {} |   } = {} | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client) { |  | ||||||
|     this.client = client |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   async get (cacheName: string, key: string): Promise<undefined | any> { |   async get (cacheName: string, key: string): Promise<undefined | any> { | ||||||
|     const cache = this.data[cacheName] |     const cache = this.data[cacheName] | ||||||
|     if (cache === undefined) return |     if (cache === undefined) return | ||||||
|  | @ -59,13 +53,11 @@ export class DefaultCacheAdapter implements ICacheAdapter { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export class RedisCacheAdapter implements ICacheAdapter { | export class RedisCacheAdapter implements ICacheAdapter { | ||||||
|   client: Client |  | ||||||
|   _redis: Promise<Redis> |   _redis: Promise<Redis> | ||||||
|   redis?: Redis |   redis?: Redis | ||||||
|   ready: boolean = false |   ready: boolean = false | ||||||
| 
 | 
 | ||||||
|   constructor (client: Client, options: RedisConnectOptions) { |   constructor (options: RedisConnectOptions) { | ||||||
|     this.client = client |  | ||||||
|     this._redis = connect(options) |     this._redis = connect(options) | ||||||
|     this._redis.then( |     this._redis.then( | ||||||
|       redis => { |       redis => { | ||||||
|  |  | ||||||
|  | @ -29,7 +29,7 @@ export class Client extends EventEmitter { | ||||||
|   user?: User |   user?: User | ||||||
|   ping = 0 |   ping = 0 | ||||||
|   token?: string |   token?: string | ||||||
|   cache: ICacheAdapter = new DefaultCacheAdapter(this) |   cache: ICacheAdapter = new DefaultCacheAdapter() | ||||||
|   intents?: GatewayIntents[] |   intents?: GatewayIntents[] | ||||||
|   forceNewSession?: boolean |   forceNewSession?: boolean | ||||||
|   users: UserManager = new UserManager(this) |   users: UserManager = new UserManager(this) | ||||||
|  |  | ||||||
|  | @ -1,33 +1,24 @@ | ||||||
| import { Client, GuildTextChannel, GatewayIntents, Message, DefaultCacheAdapter, ClientPresence, Member, Role, GuildChannel, TextChannel, Embed, Guild } from '../../mod.ts'; | import { Client, GuildTextChannel, Message, RedisCacheAdapter, ClientPresence, Member, Role, GuildChannel, TextChannel, Embed, Guild } from '../../mod.ts'; | ||||||
| import { Intents } from "../utils/intents.ts"; | import { Intents } from "../utils/intents.ts"; | ||||||
| import { TOKEN } from './config.ts' | import { TOKEN } from './config.ts' | ||||||
| 
 | 
 | ||||||
| const client = new Client({ | const client = new Client({ | ||||||
|   presence: new ClientPresence({ |   presence: new ClientPresence({ | ||||||
|     activity: { |       name: 'Pokémon Sword', | ||||||
|       name: "Pokémon Sword", |  | ||||||
|       type: 'COMPETING' |       type: 'COMPETING' | ||||||
|     } |  | ||||||
|   }), |   }), | ||||||
|  |   // cache: new RedisCacheAdapter({
 | ||||||
|  |   //   hostname: '127.0.0.1',
 | ||||||
|  |   //   port: 6379
 | ||||||
|  |   // }) // Defaults to in-memory Caching
 | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| client.setAdapter(new DefaultCacheAdapter(client)) |  | ||||||
| 
 |  | ||||||
| client.on('ready', () => { | client.on('ready', () => { | ||||||
|   console.log(`[Login] Logged in as ${client.user?.tag}!`) |   console.log(`[Login] Logged in as ${client.user?.tag}!`) | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| client.on('debug', console.log) | client.on('debug', console.log) | ||||||
| 
 | 
 | ||||||
| client.on('channelPinsUpdate', (before: TextChannel, after: TextChannel) => { |  | ||||||
|   console.log(before.send('', { |  | ||||||
|     embed: new Embed({ |  | ||||||
|       title: 'Test', |  | ||||||
|       description: 'Test Embed' |  | ||||||
|     }) |  | ||||||
|   })) |  | ||||||
| }) |  | ||||||
| 
 |  | ||||||
| client.on('channelUpdate', (before: GuildTextChannel, after: GuildTextChannel) => { | client.on('channelUpdate', (before: GuildTextChannel, after: GuildTextChannel) => { | ||||||
|   console.log(before.send('', { |   console.log(before.send('', { | ||||||
|     embed: new Embed({ |     embed: new Embed({ | ||||||
|  | @ -39,31 +30,31 @@ client.on('channelUpdate', (before: GuildTextChannel, after: GuildTextChannel) = | ||||||
| 
 | 
 | ||||||
| client.on('messageCreate', async (msg: Message) => { | client.on('messageCreate', async (msg: Message) => { | ||||||
|   if (msg.author.bot === true) return |   if (msg.author.bot === true) return | ||||||
|   if (msg.content === "!ping") { |   if (msg.content === '!ping') { | ||||||
|     msg.reply(`Pong! Ping: ${client.ping}ms`) |     msg.reply(`Pong! Ping: ${client.ping}ms`) | ||||||
|   } else if (msg.content === "!members") { |   } else if (msg.content === '!members') { | ||||||
|     const col = await msg.guild?.members.collection() |     const col = await msg.guild?.members.collection() | ||||||
|     const data = col?.array().map((c: Member, i: number) => { |     const data = col?.array().map((c: Member, i: number) => { | ||||||
|       return `${i + 1}. ${c.user.tag}` |       return `${i + 1}. ${c.user.tag}` | ||||||
|     }).join("\n") as string |     }).join("\n") as string | ||||||
|     msg.channel.send("Member List:\n" + data) |     msg.channel.send("Member List:\n" + data) | ||||||
|   } else if (msg.content === "!guilds") { |   } else if (msg.content === '!guilds') { | ||||||
|     const guilds = await msg.client.guilds.collection() |     const guilds = await msg.client.guilds.collection() | ||||||
|     msg.channel.send("Guild List:\n" + (guilds.array().map((c: Guild, i: number) => { |     msg.channel.send('Guild List:\n' + (guilds.array().map((c: Guild, i: number) => { | ||||||
|       return `${i + 1}. ${c.name} - ${c.memberCount} members` |       return `${i + 1}. ${c.name} - ${c.memberCount} members` | ||||||
|     }).join("\n") as string)) |     }).join("\n") as string)) | ||||||
|   } else if (msg.content === "!roles") { |   } else if (msg.content === '!roles') { | ||||||
|     const col = await msg.guild?.roles.collection() |     const col = await msg.guild?.roles.collection() | ||||||
|     const data = col?.array().map((c: Role, i: number) => { |     const data = col?.array().map((c: Role, i: number) => { | ||||||
|       return `${i + 1}. ${c.name}` |       return `${i + 1}. ${c.name}` | ||||||
|     }).join("\n") as string |     }).join("\n") as string | ||||||
|     msg.channel.send("Roles List:\n" + data) |     msg.channel.send("Roles List:\n" + data) | ||||||
|   } else if (msg.content === "!channels") { |   } else if (msg.content === '!channels') { | ||||||
|     const col = await msg.guild?.channels.array() |     const col = await msg.guild?.channels.array() | ||||||
|     const data = col?.map((c: GuildChannel, i: number) => { |     const data = col?.map((c: GuildChannel, i: number) => { | ||||||
|       return `${i + 1}. ${c.name}` |       return `${i + 1}. ${c.name}` | ||||||
|     }).join("\n") as string |     }).join("\n") as string | ||||||
|     msg.channel.send("Channels List:\n" + data) |     msg.channel.send('Channels List:\n' + data) | ||||||
|   } |   } | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue