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
				
			
		|  | @ -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