Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.diamondfire.helpbot.bot;

import com.diamondfire.helpbot.HelpBot;
import com.diamondfire.helpbot.bot.command.CommandHandler;
import com.diamondfire.helpbot.bot.command.impl.codeblock.*;
import com.diamondfire.helpbot.bot.command.impl.other.*;
Expand Down Expand Up @@ -110,7 +109,8 @@ public static void initialize() throws LoginException {
new ExcusedStaffCommand(),
new SupportBannedPlayersCommand(),
new DiscussionMuteCommand(),
new NbsCommand()
new NbsCommand(),
new DailySessionsCommand()
);

JDABuilder builder = JDABuilder.createDefault(config.getToken())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.diamondfire.helpbot.bot.command.impl.stats.support;

import com.diamondfire.helpbot.bot.command.argument.ArgumentSet;
import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer;
import com.diamondfire.helpbot.bot.command.argument.impl.types.DateArgument;
import com.diamondfire.helpbot.bot.command.help.*;
import com.diamondfire.helpbot.bot.command.impl.Command;
import com.diamondfire.helpbot.bot.command.permissions.Permission;
import com.diamondfire.helpbot.bot.events.CommandEvent;
import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery;
import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery;
import com.diamondfire.helpbot.sys.graph.graphable.*;
import com.diamondfire.helpbot.sys.graph.impl.ChartGraphBuilder;
import com.diamondfire.helpbot.util.DateUtil;

import java.sql.ResultSet;
import java.time.Instant;
import java.util.*;


public class DailySessionsCommand extends Command {

@Override
public String getName() {
return "dailysessions";
}

@Override
public String[] getAliases() {
return new String[]{"ds"};
}

@Override
public HelpContext getHelpContext() {
return new HelpContext()
.description("Generates a graph of all sessions done in a specific day.")
.category(CommandCategory.SUPPORT)
.addArgument(
new HelpContextArgument()
.name("date")
.optional()
);
}

@Override
public ArgumentSet compileArguments() {
return new ArgumentSet()
.addArgument("date",
new SingleArgumentContainer<>(new DateArgument()).optional(null));

}

@Override
public Permission getPermission() {
return Permission.SUPPORT;
}

@Override
public void run(CommandEvent event) {
Date date;
if (event.getArgument("date") == null) {
date = Date.from(Instant.now());
} else {
date = event.getArgument("date");
}

java.sql.Date sqlDate = DateUtil.toSqlDate(date);

new DatabaseQuery()
.query(new BasicQuery("SELECT hour(time) AS time, COUNT(*) AS count\n" +
"FROM hypercube.support_sessions\n" +
"WHERE DATE(time) = ?\n" +
"GROUP BY hour(time)\n" +
"ORDER BY time",
(statement) -> statement.setDate(1, sqlDate))
)
.compile()
.run((query) -> {
Map<GraphableEntry<?>, Integer> dates = new LinkedHashMap<>();
ResultSet set = query.getResult();

for (int i = 0; i < 25; i++) {
boolean end = set.next();
String timedisplay = i + "";
if (i < 10) {
timedisplay = "0" + timedisplay;
}
dates.put(new StringEntry(timedisplay + ":00"), !end ? 0 : set.getInt("count"));
}

event.getChannel().sendFile(new ChartGraphBuilder()
.setGraphName(String.format("Total sessions on %s", date))
.createGraph(dates)).queue();

});

}

}