snipe-list.cache.ts 872 B

1234567891011121314151617181920212223242526272829303132333435
  1. import fs from 'fs';
  2. import path from 'path';
  3. import { logger, SNIPE_LIST_REFRESH_INTERVAL } from '../helpers';
  4. export class SnipeListCache {
  5. private snipeList: string[] = [];
  6. private fileLocation = path.join(__dirname, '../snipe-list.txt');
  7. constructor() {
  8. setInterval(() => this.loadSnipeList(), SNIPE_LIST_REFRESH_INTERVAL);
  9. }
  10. public init() {
  11. this.loadSnipeList();
  12. }
  13. public isInList(mint: string) {
  14. return this.snipeList.includes(mint);
  15. }
  16. private loadSnipeList() {
  17. logger.trace(`Refreshing snipe list...`);
  18. const count = this.snipeList.length;
  19. const data = fs.readFileSync(this.fileLocation, 'utf-8');
  20. this.snipeList = data
  21. .split('\n')
  22. .map((a) => a.trim())
  23. .filter((a) => a);
  24. if (this.snipeList.length != count) {
  25. logger.info(`Loaded snipe list: ${this.snipeList.length}`);
  26. }
  27. }
  28. }