aboutsummaryrefslogtreecommitdiff
path: root/commands/mod/sticky.js
diff options
context:
space:
mode:
authorame <[email protected]>2023-09-26 23:12:35 -0500
committerame <[email protected]>2023-09-26 23:12:35 -0500
commitadc05627661e4b229037dc1e43410846078f4996 (patch)
tree8bbd7d34085007e36207f8e8c5976b7de64a7b3b /commands/mod/sticky.js
init
Diffstat (limited to 'commands/mod/sticky.js')
-rw-r--r--commands/mod/sticky.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/commands/mod/sticky.js b/commands/mod/sticky.js
new file mode 100644
index 0000000..b3dc055
--- /dev/null
+++ b/commands/mod/sticky.js
@@ -0,0 +1,57 @@
+const fs = require('fs')
+const path = require("path");
+const db = require("../../src/db")
+let config_loc = __filename+".json"
+let config = JSON.parse(fs.readFileSync(config_loc))
+const {upload_limit} = require("../../src/util")
+module.exports = {
+ name : "sticky",
+ command: ["sticky"],
+ mod_only: true,
+ config:config,
+ config_loc:config_loc,
+ async main (client,Discord,message,args){
+ switch(args[0]){
+ case 'add':
+ case 'a':
+ if(args.length<3){
+ message.reply("not enough parameters, try `sns help sticky`")
+ break;
+ }
+ db.Sticky.create({channel:args[1],message:args[2],last_message:'null',embed:args.includes("embed"),embed_color:config.embed_color});
+ message.react("✅")
+ break;
+ case 'rem':
+ case 'remove':
+ case 'r':
+ if(args.length<2){
+ message.reply("not enough parameters, try `sns help sticky`")
+ break;
+ }
+ let initial = await db.Sticky.count()
+ await db.Sticky.destroy({
+ where: {
+ channel: args[1]
+ }
+ });
+ message.reply("removed "+(initial-(await db.Sticky.count()))+" item(s)")
+ break;
+ case 'dump':
+ case 'list':
+ let list = await db.Sticky.findAll()
+ let flist = "channelid : message : last message\n"
+ for(let l of list)
+ flist+=l.channel+" : "+l.message+" : "+l.last_message+"\n"
+ let filename = "/tmp/sticky.json"
+ fs.writeFileSync(filename,flist)
+ 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")
+ message.reply({files:[filename]})
+ break;
+ default:
+ message.reply("unknown action, try `sns help sticky`")
+ }
+
+ },
+} \ No newline at end of file