diff options
-rw-r--r-- | a | 6 | ||||
-rw-r--r-- | b | 5 | ||||
-rw-r--r-- | commands/games/battleship.js | 3 | ||||
-rw-r--r-- | commands/mod/defaults/strip-roles.js.json | 2 | ||||
-rw-r--r-- | commands/mod/strip-roles.js | 35 | ||||
-rw-r--r-- | commands/util/emote.js | 20 | ||||
-rw-r--r-- | events/message.js | 49 | ||||
-rw-r--r-- | index.js | 1 | ||||
-rw-r--r-- | src/util.js | 3 |
9 files changed, 119 insertions, 5 deletions
@@ -0,0 +1,6 @@ +[3922104] running under the name sns-chan +db connected +listening at http://localhost:7001 +loaded 12 slash commands for 2 guilds, and denied 1 guilds +online! +Possible AsyncEventEmitter memory leak detected. 11 error listeners added to WebSocketShard. Use emitter.setMaxListeners() to increase the limit. @@ -0,0 +1,5 @@ +[1933911] running under the name sns-chan +db connected +listening at http://localhost:7001 +loaded 12 slash commands for 2 guilds, and denied 1 guilds +online! diff --git a/commands/games/battleship.js b/commands/games/battleship.js index 2d71f03..136124a 100644 --- a/commands/games/battleship.js +++ b/commands/games/battleship.js @@ -164,7 +164,8 @@ module.exports = { if(bttl_db.length==0) return args.message.reply({content:"id not found!",ephemeral:true}) } - let game_test = db.BattleShip.findAll({where:{p1_id:args.message.author.id,status:"open"}}) + let game_test = await db.BattleShip.findAll({where:{p1_id:args.message.author.id,status:"open"}}) + if(game_test.length!=0) return args.message.reply({content:"you are already in a game!",ephemeral:true}) diff --git a/commands/mod/defaults/strip-roles.js.json b/commands/mod/defaults/strip-roles.js.json new file mode 100644 index 0000000..ef0c9a2 --- /dev/null +++ b/commands/mod/defaults/strip-roles.js.json @@ -0,0 +1,2 @@ +{"cooldown":-1,"desc":"Remove all roles from a user","restrict":[],"restricted":[], +"usage":"{command} [user, ...]"}
\ No newline at end of file diff --git a/commands/mod/strip-roles.js b/commands/mod/strip-roles.js new file mode 100644 index 0000000..6432919 --- /dev/null +++ b/commands/mod/strip-roles.js @@ -0,0 +1,35 @@ +const Discord = require("discord.js") +const { EmbedBuilder } = require("discord.js"); +const { PermissionsBitField } = require('discord.js'); +const settings = require("../../src/settings") +const fs = require('fs') +let config_loc = __filename+".json" +let config = JSON.parse(fs.readFileSync(config_loc)) +module.exports = { + name: "strip-roles", + command: ["strip-roles"], + mod_only:true, + config:config, + config_loc:config_loc, + async main(client,Discord,message,args) { + let mentioned = []; + let failed = 0; + message.mentions.users.map( o => { + try{ + message.guild.members.cache.get(o.id).roles.remove(member.roles.cache) + }catch(e){ + failed++ + } + }) + if(failed!=0) message.reply("failed "+failed+" modifications (permission error)") + //this.exec(client,{message:message,user:user}) + }, + exec(client,param){ + const motw = new EmbedBuilder() + .setTitle("Member of the Week") + .setColor(settings.defaultColor) + .setDescription(param.name) + .setImage(param.image); + param.message.channel.send({ embeds: [motw] }); + } +};
\ No newline at end of file diff --git a/commands/util/emote.js b/commands/util/emote.js index a6f4430..1b69c95 100644 --- a/commands/util/emote.js +++ b/commands/util/emote.js @@ -25,6 +25,24 @@ module.exports = { else interaction.reply({content:"invalid emote!", ephemeral: true}) }, + async get_pronouns(message, userid){ + let pronoun = null + let count = 0 + /* + would add more pronouns, but we dont have any pronoun roles + */ + message.member.roles.cache.some((r) => { + switch(r.name.toLowerCase()){ + case "she/her": + pronoun = "herself"; count++ + break; + case "he/him": + pronoun = "himself"; count++ + break; + } + }) + return count == 1? pronoun : "themselves" + }, async exec(client,param){ let msg = ""; if(Object.keys(config.avaliable_multi.value).includes(param.emote)){ @@ -32,7 +50,7 @@ module.exports = { if(!param.mentioned) return param.message.reply({content:"please mention someone", ephemeral: true}) if(param.mentioned.id==param.message.author.id) - msg="<@"+param.message.author.id+"> "+config.avaliable_multi.value[param.emote]+" themselves" + msg="<@"+param.message.author.id+"> "+config.avaliable_multi.value[param.emote]+" "+await this.get_pronouns(param.message, param.message.author.id) else if(param.mentioned.id=="762561860150362142") msg="<@"+param.message.author.id+"> "+config.avaliable_multi.value[param.emote]+" me!" else diff --git a/events/message.js b/events/message.js index facd708..b93f081 100644 --- a/events/message.js +++ b/events/message.js @@ -5,6 +5,7 @@ const { parse_inp } = require("../src/util") const { channel } = require('diagnostics_channel'); const { PermissionsBitField } = require('discord.js'); const { EmbedBuilder } = require("discord.js"); +const util = require("../src/util") let settings = require('../src/settings') let config_loc = __filename+".json" module.exports = { @@ -17,13 +18,55 @@ module.exports = { return require("./dm").main(client,Discord,message) if(!settings["allowed-servers"].includes(message.guild.id)||message.author.bot||message.member==null) return; + + //spam messages + for(let i = 0; i < global.recent_messages.length; i++){ + let diff = util.diff((new Date(message.createdTimestamp)).getUTCSeconds(),(new Date(global.recent_messages[i].createdTimestamp)).getUTCSeconds()); + + if(diff>2){ + global.recent_messages.splice(i,1); + i = -1; + } + } + + let matching_ids = []; + for(let i = 0; i < global.recent_messages.length; i++){ + let m = global.recent_messages[i]; + if((m.content==message.content||util.similarity(m.content,message.content))&&m.author==message.author){ + matching_ids.push(m); + } + } + global.recent_messages.push(message) + if(matching_ids.length > 3){ + //let temp_msg = global.recent_messages; + global.recent_messages = global.recent_messages.filter(x => x.author != message.author) + let could_timeout = true + try{ + await message.member.timeout(60000) + } catch (e) { + could_timeout = false; + } + for(let mm of matching_ids){ + mm.delete(); + //try { await mm.delete(); } catch (e) {} + } + + let embed = new EmbedBuilder() + .setColor(settings.defaultColor) + .setTitle("Spam:(") + .setDescription("<@"+message.author.id+"> sent "+matching_ids.length+" messages, similar to or matching \n`"+message.content+"`") + + global.channels["admin-chan"].send({ embeds: [embed]}) + } + //done w/ spam + //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; + if(message.content.toLowerCase().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}}) } @@ -66,7 +109,7 @@ module.exports = { } //done w/ auto reactions - + //deal with commands let remove = function(msg) {setTimeout(async()=>{try{await msg.delete()}catch(e){}},config["error-timeout"].value)} let date = new Date() @@ -109,4 +152,4 @@ module.exports = { //done w/ commands }) }, -}
\ No newline at end of file +} @@ -144,6 +144,7 @@ fs.readdirSync("./commands/").forEach(folder => { client.env = process.env global.commands = commands; global.s_commands = s_commands; +global.recent_messages = []; fs.readdirSync("./events/").forEach(file => { if(path.extname(file)==".js") diff --git a/src/util.js b/src/util.js index ef1cf50..3321744 100644 --- a/src/util.js +++ b/src/util.js @@ -1,6 +1,9 @@ const rem_emp = function (e) {return e !== "";} module.exports = { + diff(a,b){ + return (a>b)?(a-b):(b-a); + }, upload_limit(guild){ //https://stackoverflow.com/questions/66396146/get-channels-filesize-limit switch (guild.premiumTier) { |