Advertisement
Guest User

h bot

a guest
Feb 1st, 2021
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Copyleft (C) Kamila Szewczyk, 2020.
  2. // All wrongs reserved.
  3.  
  4. import Discord from'discord.js'
  5. import fs from'fs'
  6. import cbor from'cbor'
  7. const client=new Discord.Client()
  8. let data:Map<string, number>=new Map(cbor.decode(fs.readFileSync('db.json')))
  9. data[Symbol.iterator]=function*(){yield*[...this.entries()].sort((a,b)=>b[1]-a[1]);}
  10. const possesive=(nick:string)=>nick.endsWith("s")?nick+"'":nick+"'s"
  11. const get_def=(key:string)=>data.has(key)?data.get(key)!:0
  12. const extract_ping=(msg:Discord.Message)=>msg.mentions.members?.filter(x=>x.user.id!=client.user?.id).first()
  13. const id2name=(id:string)=>(client.users.cache.get(id)?.tag)||id
  14. const command=(msg:Discord.Message)=>{
  15.     const ping=extract_ping(msg)
  16.     if(ping!==undefined){msg.channel.send(possesive(ping.user.username)+" h score: "+get_def(ping.user.id));return;}
  17.     if(msg.content.endsWith("top")){msg.channel.send([...data].slice(0,10).map(k=>((k,v)=>`**${k}**: ${v} h`)(id2name(k[0]),k[1])).join('\n'));}
  18. }
  19. client.on('message',msg=>(!msg.author.bot&&(msg.guild==null||(msg.mentions.members!=null&&client.user!=null&&msg.mentions.members.filter(x=>x.user.id==client.user?.id).size>=1)))&&command(msg))
  20. client.on('message',msg=>msg.content.match(/^[hHħhℏ]+$/)!=null&&data.set(msg.author.id,get_def(msg.author.id)+1))
  21. client.login(JSON.parse(fs.readFileSync('bot.json').toString()).token)
  22. setInterval(async()=>fs.writeFile('db.json',cbor.encode(Array.from(data.entries())),x=>x),10000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement