diff options
-rw-r--r-- | commands/util/defaults/track.js.json | 2 | ||||
-rw-r--r-- | commands/util/status.js | 4 | ||||
-rw-r--r-- | commands/util/track.js | 125 | ||||
-rw-r--r-- | events/interaction.js | 11 | ||||
-rw-r--r-- | events/message.js | 12 | ||||
-rw-r--r-- | src/db.js | 7 |
6 files changed, 158 insertions, 3 deletions
diff --git a/commands/util/defaults/track.js.json b/commands/util/defaults/track.js.json new file mode 100644 index 0000000..4ea8ff4 --- /dev/null +++ b/commands/util/defaults/track.js.json @@ -0,0 +1,2 @@ +{"cooldown":-1,"desc":"Track a certain word, or opt-in","restrict":[],"restricted":[], +"usage":"{command} {opt-in | opt-out | del | reg <words..> | unreg <words..>, list}"}
\ No newline at end of file diff --git a/commands/util/status.js b/commands/util/status.js index 2980618..96c065a 100644 --- a/commands/util/status.js +++ b/commands/util/status.js @@ -24,6 +24,7 @@ module.exports = { async exec(client,message){ getLastCommit(async (err,commit)=>{ let changed = execSync('git --no-pager diff --minimal --name-only').toString().split('\n').filter((s) => s!='') + let changed_d = execSync('git diff --shortstat --minimal').toString() let seconds = Math.floor(message.client.uptime / 1000); let minutes = Math.floor(seconds / 60); let hours = Math.floor(minutes / 60); @@ -38,6 +39,7 @@ module.exports = { .setLabel('Vote') .setStyle(ButtonStyle.Link) .setURL('https://top.gg/servers/486957006628847626/vote') + // /*const twitter = new ButtonBuilder() //0% chance i will call this 𝕏 .setLabel('Twitter') .setStyle(ButtonStyle.Link) @@ -59,7 +61,7 @@ module.exports = { .setTitle("Server info") .setDescription(uptime+"\n"+sys) .setColor(settings.defaultColor) - .setFooter({text:"running "+commit.shortHash+" ("+commit.branch+") + " + changed.length + " uncommited files"}) + .setFooter({text:"running "+commit.shortHash+" ("+commit.branch+") + (live)" + (changed.length>0?changed_d:"")}) message.reply({embeds:[emoteembed],components:[row]}) }) } diff --git a/commands/util/track.js b/commands/util/track.js new file mode 100644 index 0000000..91b9e7f --- /dev/null +++ b/commands/util/track.js @@ -0,0 +1,125 @@ +const fs = require('fs') +const path = require("path"); +let config_loc = __filename+".json" +const { PermissionsBitField } = require('discord.js'); +let config = JSON.parse(fs.readFileSync(config_loc)) +let db = require("../../src/db") +const {upload_limit} = require("../../src/util") +module.exports = { + name : "track", + command: ["track"], + mod_only: false, + config:config, + config_loc:config_loc, + async main (client,Discord,message,args){ + if((args[0]=="reg"||args[0]=="unreg")&&args.length < 1){ + return message.reply("please enter a word to (un)register") + } + let action = args[0]; + args.shift(); + this.exec(client,message,{action:action,other:args}) + }, + s_options:[{type:"sub",name:"opt-in",options:[]}, + {type:"sub",name:"opt-out",options:[]}, + {type:"sub",name:"del",options:[]}, + {type:"sub",name:"list",options:[]}, + {type:"sub",name:"reg",options:[{type:"string",name:"word",desc:"word to add",required:true,autocomplete:false}]}, + {type:"sub",name:"unreg",options:[{type:"string",name:"word",desc:"word to remove",required:true,autocomplete: + async (message)=>{ + let list = [] + let d = (await db.Track.findAll({where:{user:message.author.id}}))[0] + if(d==null) return []; + for(let u of JSON.parse(d.words)) list.push(u.word); + return list; + } + }]}, + ], + async s_main (client,Discord,interaction){ + let action = interaction.options.getSubcommand() + let mess = interaction.options.getString("word") + await this.exec(client,interaction,{action:action,other:[mess]}) + //await interaction.reply({ content:'sent', ephemeral: true }) + //interaction.deleteReply() + }, + async exec(client,message,info){ + let words; + let qu = {where:{user:message.author.id}} + let entry = (await db.Track.findAll(qu)) + switch(info.action){ + case "opt-in": + if(entry.length==0){ + await db.Track.create({ + user:message.author.id, + words:"[]", + track:true, + }) + return message.reply("registered!") + } + + await db.Track.update({track:true},qu); + return message.reply("tracking enabled!") + break; + case "opt-out": + if(entry.length==0){ + return message.reply("you are not opted in") + } + + await db.Track.update({track:false},qu); + return message.reply("tracking disabled!") + break; + case "del": + if(entry.length==0){ + return message.reply("you are not opted in") + } + + await db.Track.destroy(qu); + return message.reply("entry deleted") + break; + case "reg": + if(entry.length==0){ + return message.reply("you are not opted in") + } + + for(let o in info.other){ + info.other[o] = {word:info.other[o].toLowerCase(),count:0} + } + + words = JSON.parse(entry[0].words) + await db.Track.update({words:JSON.stringify([...words,...info.other])},qu); + return message.reply("added "+info.other.length+" words") + break; + case "unreg": + if(entry.length==0){ + return message.reply("you are not opted in") + } + + words = JSON.parse(entry[0].words) + let newwords = [] + let removed = 0; + for(let w of words){ + if(!info.other.includes(w.word.toLowerCase())) newwords.push(w); + else removed++; + + } + await db.Track.update({words:JSON.stringify(newwords)},qu); + return message.reply("removed "+removed+" words"+(info.other.length>removed?", "+(info.other.length-removed)+" not found":"")) + break; + case "list": + if(entry.length==0){ + return message.reply("you are not opted in") + } + let mmsg = "word | count\n-------------\n"; + for(let o of JSON.parse(entry[0].words)){ + mmsg += o.word + " | " + o.count + "\n"; + } + let filename = "/tmp/"+entry[0].user+".json" + fs.writeFileSync(filename,mmsg) + let stats = fs.statSync(filename) + if(stats.size / (1024*1024) > upload_limit(message.guild)) + return message.reply("file too large:( file is "+stats.size / (1024*1024)+"mb") + return message.reply({files:[filename]}) + break; + } + //return info.id.send(info.echo) + } +}
\ No newline at end of file diff --git a/events/interaction.js b/events/interaction.js index c65ecb7..b3a5be1 100644 --- a/events/interaction.js +++ b/events/interaction.js @@ -16,6 +16,7 @@ module.exports = { if(!settings["allowed-servers"].includes(interaction.guild.id)) return console.log("denied interaction from (guild)"+interaction.guild.id) let date = new Date() + interaction.author = interaction.user if(interaction.isChatInputCommand()){ await interaction.guild.members.fetch() @@ -27,7 +28,7 @@ module.exports = { return interaction.reply({content:"you cannot send this here! try `sns help` for more info",ephemeral:true}) if(command==null) return; - interaction.author = interaction.user + let uid = interaction.user.id; if(!mod&&command.command.last_command[uid]!=null&&(date.getTime()-command.command.last_command[uid].getTime())/1000<command.command.config.cooldown) @@ -41,8 +42,14 @@ module.exports = { const focused = interaction.options.getFocused(true); let command = global.s_commands.find(o => o.name === interaction.commandName) + if(interaction.options._subcommand!=null){ + //command = command.options.find(o => o.name === interaction.options._subcommand).options.find(o => o.name === focused.name) + command = (command.command.s_options.find(o => o.name === interaction.options._subcommand)) + command.opt = command.options; + } let subcommand = command.opt.find(o => o.name === focused.name) - let autocomplete = (typeof subcommand.autocomplete === 'function' ? await subcommand.autocomplete() : subcommand.autocomplete); + + let autocomplete = (typeof subcommand.autocomplete === 'function' ? await subcommand.autocomplete(interaction) : subcommand.autocomplete); const filtered = autocomplete.filter(choice => choice.startsWith(focused.value)); if(filtered.length>25) filtered.length=25 diff --git a/events/message.js b/events/message.js index 59e79ef..facd708 100644 --- a/events/message.js +++ b/events/message.js @@ -17,6 +17,18 @@ module.exports = { return require("./dm").main(client,Discord,message) if(!settings["allowed-servers"].includes(message.guild.id)||message.author.bot||message.member==null) return; + //track message + let utrack = await db.Track.findAll({where:{user:message.author.id,track:true}}) + if(utrack.length!=0){ + utrack = utrack[0]; + let words = JSON.parse(utrack.words); + for(let w of words){ + if(message.content.includes(w.word)) w.count+=message.content.split(w.word).length-1; + } + db.Track.update({words:JSON.stringify(words)},{where:{user:message.author.id,track:true}}) + } + //done w/ track + //handle sticky messages let stickies = await db.Sticky.findAll(); for(let s of stickies){ @@ -59,6 +59,13 @@ db.BattleShip = _db_raw.define('BattleShip', { }, { }); +db.Track = _db_raw.define('Track', { + user: DataTypes.TEXT, + words: DataTypes.TEXT, + track: DataTypes.BOOLEAN, +}, { +}); + try { //db.BattleShip.sync({force:true}) db._raw.authenticate(); |