DiscordBot.mainJDA=event.getJDA();// refresh it? //no need, everything's getJDA() is the same jda basis but audioplayer's still using it; need to migrate to store in guildmusicmanager
ResultSetuRs=s.executeQuery("SELECT reports FROM users WHERE id = "+author.getId()+";");
if(uRs.next()){//checks null at the same time
if(uRs.getString(1).split("\n").length>=5){
channel.sendMessage("You are banned from using the bot.").queue();
DiscordBot.logger.info("[WARN] "+author.getName()+" ("+author.getId()+") tried to execute "+msg.getContentDisplay()+" but was banned.");
return;
}
}
uRs.close();
//check perms
longperm=MiscUtils.getActivePerms(s,channel,cmd);
Stringperms=cmd.hasSubCommand()?null:MiscUtils.getMissingPerms(perm,cmd.getRequiredBotUserLevel(),event.getMember(),channel);//pass it to the subcommand handler to handle instead
if(cmd.isDisabled())perms="DISABLED";//override if disabled by code
if(perms==null||event.getAuthor().getId().equals(DiscordBot.OwnerID)){//owner overrides perms for convenience
//execute async
cmd.executeAsync(channel,author,msg,Arrays.copyOfRange(args,1,args.length),r->{//catch all exceptions? //should have actually
+msg.getContentDisplay()+(r.getRemarks()==null?".":". ("+r.getRemarks()+")"));//logging has to be before sendMessage, or else if no permission it will just quit
});//dont know if async will screw anything up //wont, TODO log date and which server executed the command also?
return;
}elseif(perms.equals("DISABLED")){
author.openPrivateChannel().queue(c->//notify user whats wrong if possible
c.sendMessage("Sorry, but the command `"+msg.getContentDisplay()+"` is disabled in the channel `#"+channel.getName()+"`.").queue());
msg.addReaction(Emoji.fromUnicode("❎")).queue();//instead of sending messages, react instead to avoid clutter (which is what most ppl disable a bot in a channel for)
eb.appendDescription("Total members (cached): `"+DiscordBot.mainJDA.getUserCache().size()+(DiscordBot.mainJDA.getShardManager()==null?"":"/"+DiscordBot.mainJDA.getShardManager().getShards().stream().mapToLong(jda->jda.getUserCache().size()).sum())+"`\n");
eb.appendDescription("DM `"+DiscordBot.mainJDA.getUserById(DiscordBot.OwnerID).getAsTag()+"` if you have any questions!\n");
eb.appendDescription("To get a list of commands, do `"+prefix+"help`.");
DiscordBot.logger.trace("[EDIT] "+guildinfo+System.lineSeparator()+" "+msg+System.lineSeparator()+" Full edited msg: "+msg.getContentDisplay());
}
}
@Override
publicvoidonUserActivityStart(UserActivityStartEventevent){//store presence for checking osu pp
Activityosu=event.getNewActivity();
if(osu!=null&&osu.getName().equals("osu!")&&osu.isRich()//if need to include other games and details, just remove this if clause and change sGame below
try(Connectioncon=DiscordBot.db.getConnection()){//DONE do i need to close the statement?
PreparedStatements=con.prepareStatement("INSERT INTO users(id, game) VALUES ("+event.getUser().getId()+", ?) ON CONFLICT(id) DO UPDATE SET game = ? WHERE game <> ?;");//prevent blank updates
publicvoidonGuildVoiceUpdate(GuildVoiceUpdateEventevent){// theoretically i dont need to check if lastMusicCmd has the entry or not, as it must have one to trigger this
"The bot has been moved to an empty channel, the player is now paused.\nThe queue will be cleared in 1 minute if there is no activity.")
.queue();
waitActivity(event.getGuild());
}else{//moved bot to channel with ppl
event.getGuild().getAudioManager().openAudioConnection(event.getChannelJoined());//seems to need explicit reconnect on bot move, it gets stuck on attempting to reconnect otherwise; probably would be fixed soon but hot patch for now