Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> { //no need to be a global variable since i dont need to access it
try {
FileOutputStream out = new FileOutputStream(System.getProperty("user.dir") + File.separator + "testAnimePicCache.bin");
ObjectOutputStream oos = new ObjectOutputStream(out);
oos.writeObject(EventListener.testAnimePicCache);
oos.flush();
oos.close();
} catch (IOException e) {
e.printStackTrace();
}
}, 1, 5, TimeUnit.MINUTES);*/
// DEPRECATED //or is it? make unmodifiable instead
ModID.add("165403578133905408");
ModID.add("187714189672841216");
ModID.add("204587986724192257");// hyper
ModID.add("194112515859283968");// bond
ModID.add("214270819793108993");// emma
ModID.add("209883960522702848");// M4
ModID.add("237546287388426242");// haoiscoll
ModID.add("264612287048843264");// kanade
ModID.add("254509414600409088");// shii
ModID.add(OwnerID);
logExcemptID.add(BotID);
}
privatestaticvoidinitDB(){//init guild settings when do !desp settings for the first time? //dont really need coz im doing upsert for all values anyways
HikariConfigdbConf=newHikariConfig();
dbConf.setJdbcUrl("jdbc:sqlite:data.db");
dbConf.setIdleTimeout(45000);
dbConf.setMaxLifetime(60000);
dbConf.setMaximumPoolSize(10);
//dbConf.setMaximumPoolSize(25); //for deployment in server
db=newHikariDataSource(dbConf);
try(Connectioncon=db.getConnection()){
Statements=con.createStatement();
s.execute("CREATE TABLE IF NOT EXISTS settings"
+"(id INTEGER PRIMARY KEY,"//performance problem using text; integer can handle long anyways
+"prefix TEXT DEFAULT '!desp ',"
+"premium INTEGER DEFAULT 0,"
+"mchannel TEXT,"//allow people to set this manually? By default, use last music cmd place
+"locale TEXT DEFAULT 'EN',"//or int? //user specific or guild specific, or user override guild?
+"shortcuts TEXT,"//use another method?
+"votepct INTEGER DEFAULT 50,"
+"looplimit INTEGER DEFAULT 1,"
+"volume INTEGER DEFAULT 100,"//premium?, is default actually 100?
+"helpdm INTEGER DEFAULT 0);");//send help to dm or not, excluding cmd help(?)
//add logexempt?
PreparedStatementpragma=con.prepareStatement("SELECT name FROM pragma_table_info('perms_' || ?);");//NOTE: sqlite does not support changing default values, beware when adding new commands
Stringcreate="CREATE TABLE perms_"+entry.getKey().toLowerCase()+" (id INTEGER PRIMARY KEY, _GLOBAL_ TEXT DEFAULT '0\n', ";//perms for a category are always default no restraints
join.add("\""+node.getKey()+"\" TEXT DEFAULT '"+((0L<<32)|(Permission.getRaw(node.getValue())&0xffffffffL))+"\n'");//initialize with no permission deny override, permissions allow //needs to be text so that channel overrides delimiter can be stored
}
create+=join.toString()+");";
s.execute(create);
//DONE? create table
}else{
if(!nodes.isEmpty()){//which means there is new subCmd/cmd
s.execute("ALTER TABLE perms_"+entry.getKey().toLowerCase()+" ADD COLUMN \""+node.getKey()+"\" TEXT DEFAULT '"+((0L<<32)|(Permission.getRaw(node.getValue())&0xffffffffL))+"\n';");//not able to prep statement coz its column name
s.close();
}
}
}
}
pragma.close();
//DONE TEST generate the nodes, retrieve default from fields? //what about additional commands added, use ALTER TABLE ADD COLUMN DEFAULT? I dont need to sort it according to category at all, i am not and will not be bulk printing permissions anywhere //actually i might be coz of list edited perms
//fit subnodes into sub tables, split by category so its more balanced (category as table name)?
//fields are gonna be sth like <channelid>:<perm>|<perm> etc?
//DONE store the permissions with long merged; <32bit = deny, >32bit = allow
s.execute("CREATE TABLE IF NOT EXISTS users"
+"(id INTEGER PRIMARY KEY,"
+"reports TEXT DEFAULT '',"
+"game TEXT);");//disposable, i can change it anytime
//add botmod field? if so, i can deprecate the hard coded list, but it would require querying to this table on perm checks //i need to query it to check if the user is banned anyways //subcmd need to query again, so i didnt do it; besides the modlist is gonna be too small to be significant anyways