Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyleft (C) Kamila Szewczyk, 2020.
- // All wrongs reserved.
- import Discord from'discord.js'
- import fs from'fs'
- import cbor from'cbor'
- const client=new Discord.Client()
- let data:Map<string, number>=new Map(cbor.decode(fs.readFileSync('db.json')))
- data[Symbol.iterator]=function*(){yield*[...this.entries()].sort((a,b)=>b[1]-a[1]);}
- const possesive=(nick:string)=>nick.endsWith("s")?nick+"'":nick+"'s"
- const get_def=(key:string)=>data.has(key)?data.get(key)!:0
- const extract_ping=(msg:Discord.Message)=>msg.mentions.members?.filter(x=>x.user.id!=client.user?.id).first()
- const id2name=(id:string)=>(client.users.cache.get(id)?.tag)||id
- const command=(msg:Discord.Message)=>{
- const ping=extract_ping(msg)
- if(ping!==undefined){msg.channel.send(possesive(ping.user.username)+" h score: "+get_def(ping.user.id));return;}
- 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'));}
- }
- 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))
- client.on('message',msg=>msg.content.match(/^[hHħhℏ]+$/)!=null&&data.set(msg.author.id,get_def(msg.author.id)+1))
- client.login(JSON.parse(fs.readFileSync('bot.json').toString()).token)
- 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