Search in sources :

Example 1 with ListCommand

use of com.greatmancode.legendarybot.plugin.customcommands.commands.ListCommand in project legendarybot by greatman.

the class CustomCommandsPlugin method start.

@Override
public void start() {
    log.info("Loading custom commands");
    getBot().getJDA().forEach(jda -> jda.getGuilds().forEach(g -> {
        MongoCollection<Document> collection = getBot().getMongoDatabase().getCollection(MONGO_COLLECTION_NAME);
        Map<String, String> result = new HashMap<>();
        collection.find(eq("guild_id", g.getId())).forEach((Block<Document>) document -> {
            if (document.containsKey(MONGO_DOCUMENT_NAME)) {
                ((Document) document.get(MONGO_DOCUMENT_NAME)).forEach((k, v) -> {
                    System.out.println("GUILD:" + g.getId() + " key: " + k + " value: " + v);
                    result.put(k, (String) v);
                });
            }
        });
        guildCustomCommands.put(g.getId(), result);
    }));
    getBot().getJDA().forEach(jda -> jda.addEventListener(listener));
    log.info("Custom commands loaded");
    getBot().getCommandHandler().setUnknownCommandHandler(new IUnknownCommandHandler(this));
    getBot().getCommandHandler().addCommand("createcmd", new CreateCommand(this), "Custom Commands Admin Commands");
    getBot().getCommandHandler().addCommand("removecmd", new RemoveCommand(this), "Custom Commands Admin Commands");
    getBot().getCommandHandler().addCommand("listcommands", new ListCommand(this), "General Commands");
    log.info("Plugin Custom Commands loaded!");
    log.info("Command !createcmd loaded!");
}
Also used : Document(org.bson.Document) CreateCommand(com.greatmancode.legendarybot.plugin.customcommands.commands.CreateCommand) MongoCollection(com.mongodb.client.MongoCollection) LegendaryBotPlugin(com.greatmancode.legendarybot.api.plugin.LegendaryBotPlugin) HashMap(java.util.HashMap) Filters.exists(com.mongodb.client.model.Filters.exists) Updates.set(com.mongodb.client.model.Updates.set) ListCommand(com.greatmancode.legendarybot.plugin.customcommands.commands.ListCommand) PluginWrapper(org.pf4j.PluginWrapper) RemoveCommand(com.greatmancode.legendarybot.plugin.customcommands.commands.RemoveCommand) Guild(net.dv8tion.jda.core.entities.Guild) Filters.and(com.mongodb.client.model.Filters.and) Block(com.mongodb.Block) Map(java.util.Map) Filters.eq(com.mongodb.client.model.Filters.eq) Collections(java.util.Collections) UpdateOptions(com.mongodb.client.model.UpdateOptions) Updates.unset(com.mongodb.client.model.Updates.unset) RemoveCommand(com.greatmancode.legendarybot.plugin.customcommands.commands.RemoveCommand) MongoCollection(com.mongodb.client.MongoCollection) CreateCommand(com.greatmancode.legendarybot.plugin.customcommands.commands.CreateCommand) ListCommand(com.greatmancode.legendarybot.plugin.customcommands.commands.ListCommand) Block(com.mongodb.Block) Document(org.bson.Document) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

LegendaryBotPlugin (com.greatmancode.legendarybot.api.plugin.LegendaryBotPlugin)1 CreateCommand (com.greatmancode.legendarybot.plugin.customcommands.commands.CreateCommand)1 ListCommand (com.greatmancode.legendarybot.plugin.customcommands.commands.ListCommand)1 RemoveCommand (com.greatmancode.legendarybot.plugin.customcommands.commands.RemoveCommand)1 Block (com.mongodb.Block)1 MongoCollection (com.mongodb.client.MongoCollection)1 Filters.and (com.mongodb.client.model.Filters.and)1 Filters.eq (com.mongodb.client.model.Filters.eq)1 Filters.exists (com.mongodb.client.model.Filters.exists)1 UpdateOptions (com.mongodb.client.model.UpdateOptions)1 Updates.set (com.mongodb.client.model.Updates.set)1 Updates.unset (com.mongodb.client.model.Updates.unset)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Guild (net.dv8tion.jda.core.entities.Guild)1 Document (org.bson.Document)1 PluginWrapper (org.pf4j.PluginWrapper)1