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 | ||||
| 
 | ||||
|  | ||||
| 
 | ||||
| [](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 | ||||
| 
 | ||||
|  | @ -15,25 +21,38 @@ | |||
| - [License](#license) | ||||
| 
 | ||||
| ## 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 | ||||
| import { Client } from 'https://deno.land/x/discord-deno/models/client.ts' | ||||
| import { Message } from 'https://deno.land/x/discord-deno/structures/message.ts' | ||||
| import { Client, Message, Intents } from 'https://raw.githubusercontent.com/discord-deno/discord.deno/main/mod.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') { | ||||
|     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 | ||||
| 
 | ||||
| Not made yet | ||||
| Not made yet. | ||||
| 
 | ||||
| ## Maintainer | ||||
| 
 | ||||
|  |  | |||
|  | @ -7,7 +7,6 @@ import { | |||
| } from 'https://denopkg.com/keroxp/deno-redis/mod.ts' | ||||
| 
 | ||||
| export interface ICacheAdapter { | ||||
|   client: Client | ||||
|   get: (cacheName: string, key: string) => Promise<any> | any | ||||
|   set: (cacheName: string, key: string, value: any) => Promise<any> | any | ||||
|   delete: (cacheName: string, key: string) => Promise<boolean> | boolean | ||||
|  | @ -16,15 +15,10 @@ export interface ICacheAdapter { | |||
| } | ||||
| 
 | ||||
| export class DefaultCacheAdapter implements ICacheAdapter { | ||||
|   client: Client | ||||
|   data: { | ||||
|     [name: string]: Collection<string, any> | ||||
|   } = {} | ||||
| 
 | ||||
|   constructor (client: Client) { | ||||
|     this.client = client | ||||
|   } | ||||
| 
 | ||||
|   async get (cacheName: string, key: string): Promise<undefined | any> { | ||||
|     const cache = this.data[cacheName] | ||||
|     if (cache === undefined) return | ||||
|  | @ -59,13 +53,11 @@ export class DefaultCacheAdapter implements ICacheAdapter { | |||
| } | ||||
| 
 | ||||
| export class RedisCacheAdapter implements ICacheAdapter { | ||||
|   client: Client | ||||
|   _redis: Promise<Redis> | ||||
|   redis?: Redis | ||||
|   ready: boolean = false | ||||
| 
 | ||||
|   constructor (client: Client, options: RedisConnectOptions) { | ||||
|     this.client = client | ||||
|   constructor (options: RedisConnectOptions) { | ||||
|     this._redis = connect(options) | ||||
|     this._redis.then( | ||||
|       redis => { | ||||
|  |  | |||
|  | @ -29,7 +29,7 @@ export class Client extends EventEmitter { | |||
|   user?: User | ||||
|   ping = 0 | ||||
|   token?: string | ||||
|   cache: ICacheAdapter = new DefaultCacheAdapter(this) | ||||
|   cache: ICacheAdapter = new DefaultCacheAdapter() | ||||
|   intents?: GatewayIntents[] | ||||
|   forceNewSession?: boolean | ||||
|   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 { TOKEN } from './config.ts' | ||||
| 
 | ||||
| const client = new Client({ | ||||
|   presence: new ClientPresence({ | ||||
|     activity: { | ||||
|       name: "Pokémon Sword", | ||||
|       name: 'Pokémon Sword', | ||||
|       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', () => { | ||||
|   console.log(`[Login] Logged in as ${client.user?.tag}!`) | ||||
| }) | ||||
| 
 | ||||
| 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) => { | ||||
|   console.log(before.send('', { | ||||
|     embed: new Embed({ | ||||
|  | @ -39,31 +30,31 @@ client.on('channelUpdate', (before: GuildTextChannel, after: GuildTextChannel) = | |||
| 
 | ||||
| client.on('messageCreate', async (msg: Message) => { | ||||
|   if (msg.author.bot === true) return | ||||
|   if (msg.content === "!ping") { | ||||
|   if (msg.content === '!ping') { | ||||
|     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 data = col?.array().map((c: Member, i: number) => { | ||||
|       return `${i + 1}. ${c.user.tag}` | ||||
|     }).join("\n") as string | ||||
|     msg.channel.send("Member List:\n" + data) | ||||
|   } else if (msg.content === "!guilds") { | ||||
|   } else if (msg.content === '!guilds') { | ||||
|     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` | ||||
|     }).join("\n") as string)) | ||||
|   } else if (msg.content === "!roles") { | ||||
|   } else if (msg.content === '!roles') { | ||||
|     const col = await msg.guild?.roles.collection() | ||||
|     const data = col?.array().map((c: Role, i: number) => { | ||||
|       return `${i + 1}. ${c.name}` | ||||
|     }).join("\n") as string | ||||
|     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 data = col?.map((c: GuildChannel, i: number) => { | ||||
|       return `${i + 1}. ${c.name}` | ||||
|     }).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