Search in sources :

Example 1 with GuildMessageCreateEvent

use of io.discloader.discloader.common.event.message.GuildMessageCreateEvent in project DiscLoader by R3alCl0ud.

the class MessageCreate method handle.

@Override
public void handle(SocketPacket packet) {
    MessageJSON data = this.gson.fromJson(gson.toJson(packet.d), MessageJSON.class);
    try {
        long channelID = SnowflakeUtil.parse(data.channel_id);
        ITextChannel channel = EntityRegistry.getTextChannelByID(channelID);
        if (channel == null)
            channel = EntityRegistry.getPrivateChannelByID(channelID);
        if (channel == null)
            channel = EntityRegistry.getGroupChannelByID(channelID);
        if (channel == null)
            return;
        IMessage message = EntityBuilder.getChannelFactory().buildMessage(channel, data);
        channel.getMessages().put(message.getID(), message);
        if (channel.isTyping(message.getAuthor())) {
            channel.getTyping().remove(message.getAuthor().getID());
        }
        MessageCreateEvent event = new MessageCreateEvent(message);
        loader.emit(event);
        if (channel.getType() == ChannelTypes.TEXT) {
            loader.emit(event = new GuildMessageCreateEvent(message));
        } else if (channel.getType() == ChannelTypes.DM) {
            loader.emit(event = new PrivateMessageCreateEvent(message));
        } else if (channel.getType() == ChannelTypes.GROUP) {
            loader.emit(event = new GroupMessageCreateEvent(message));
        }
        CommandHandler.handleMessageCreate(event);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ITextChannel(io.discloader.discloader.entity.channel.ITextChannel) GroupMessageCreateEvent(io.discloader.discloader.common.event.message.GroupMessageCreateEvent) GroupMessageCreateEvent(io.discloader.discloader.common.event.message.GroupMessageCreateEvent) PrivateMessageCreateEvent(io.discloader.discloader.common.event.message.PrivateMessageCreateEvent) MessageCreateEvent(io.discloader.discloader.common.event.message.MessageCreateEvent) GuildMessageCreateEvent(io.discloader.discloader.common.event.message.GuildMessageCreateEvent) MessageJSON(io.discloader.discloader.network.json.MessageJSON) IMessage(io.discloader.discloader.entity.message.IMessage) PrivateMessageCreateEvent(io.discloader.discloader.common.event.message.PrivateMessageCreateEvent) GuildMessageCreateEvent(io.discloader.discloader.common.event.message.GuildMessageCreateEvent)

Example 2 with GuildMessageCreateEvent

use of io.discloader.discloader.common.event.message.GuildMessageCreateEvent in project DiscLoader by R3alCl0ud.

the class Main method main.

public static void main(String... args) throws IOException {
    System.setProperty("http.agent", "DiscLoader");
    String content = "";
    if (new File("options.json").exists()) {
        Object[] lines = Files.readAllLines(Paths.get("./options.json")).toArray();
        for (Object line : lines) content += line;
        Options options = gson.fromJson(content, Options.class);
        token = options.auth.token;
    }
    boolean myBool = false;
    if (myBool && args.length > 1)
        System.out.println("hello");
    else
        System.out.println("fuck");
    DLOptions options = parseArgs(args);
    if (options.shards > 1) {
        ShardManager manager = new ShardManager(options);
        manager.addShardingListener(new ShardingListenerAdapter() {

            @Override
            public void onShardLaunched(ShardLaunchedEvent e) {
                LOGGER.info(String.format("Shard #%d: Launched", e.getShard().getShardID()));
                e.getShard().getLoader().addEventListener(new EventListenerAdapter() {

                    public void Ready(ReadyEvent e) {
                        for (Command command : CommandRegistry.commands.entries()) {
                            LOGGER.info(command.getUnlocalizedName());
                        }
                    }

                    @Override
                    public void RawPacket(RawEvent data) {
                        WebSocketFrame frame = data.getFrame();
                        if (data.isGateway() && frame.isTextFrame() && !frame.getPayloadText().contains("PRESENCE_UPDATE")) {
                        // LOGGER.fine(frame.getPayloadText());
                        } else if (data.isREST()) {
                            LOGGER.info(data.getHttpResponse().getBody());
                            LOGGER.info("" + data.getHttpResponse().getStatus());
                        }
                    }

                    @Override
                    public void GuildMessageCreate(GuildMessageCreateEvent e) {
                        if (e.getGuild().getID() != 282226852616077312l)
                            return;
                        if (e.getMessage().getContent().startsWith("logs")) {
                            String[] args = e.getMessage().getContent().split(" ");
                            if (args.length == 1) {
                            } else if (args.length == 2) {
                            }
                        }
                    }
                });
            }
        });
        manager.launchShards();
    } else {
        loader = new DiscLoader(options);
        loader.addEventListener(new EventListenerAdapter() {

            @Override
            public void MessageCreate(MessageCreateEvent e) {
                if (e.getMessage().getContent().equals("#$close")) {
                    e.getLoader().gateway.websocket.disconnect(1001);
                }
            }

            public void Ready(ReadyEvent e) {
                LOGGER.info(e.getLoader().user.getUsername());
                for (Command command : CommandRegistry.commands.entries()) {
                    LOGGER.info(command.getUnlocalizedName());
                }
                LOGGER.info(EntityRegistry.getGuildByID(282226852616077312l).getDefaultChannel().getName());
            // .sendMessage("testing 125");
            }

            @Override
            public void RawPacket(RawEvent data) {
                WebSocketFrame frame = data.getFrame();
                if (data.isGateway() && frame.isTextFrame() && !frame.getPayloadText().contains("PRESENCE_UPDATE")) {
                    LOGGER.info(frame.getPayloadText());
                } else if (data.isREST() && data.getHttpResponse() != null) {
                    LOGGER.info(data.getHttpResponse().getBody());
                }
            }
        });
        loader.login();
    }
}
Also used : DLOptions(io.discloader.discloader.common.DLOptions) RawEvent(io.discloader.discloader.common.event.RawEvent) ShardManager(io.discloader.discloader.common.ShardManager) ShardLaunchedEvent(io.discloader.discloader.common.event.sharding.ShardLaunchedEvent) ReadyEvent(io.discloader.discloader.common.event.ReadyEvent) MessageCreateEvent(io.discloader.discloader.common.event.message.MessageCreateEvent) GuildMessageCreateEvent(io.discloader.discloader.common.event.message.GuildMessageCreateEvent) DLOptions(io.discloader.discloader.common.DLOptions) Command(io.discloader.discloader.client.command.Command) DiscLoader(io.discloader.discloader.common.DiscLoader) EventListenerAdapter(io.discloader.discloader.common.event.EventListenerAdapter) WebSocketFrame(com.neovisionaries.ws.client.WebSocketFrame) GuildMessageCreateEvent(io.discloader.discloader.common.event.message.GuildMessageCreateEvent) File(java.io.File) ShardingListenerAdapter(io.discloader.discloader.common.event.sharding.ShardingListenerAdapter)

Aggregations

GuildMessageCreateEvent (io.discloader.discloader.common.event.message.GuildMessageCreateEvent)2 MessageCreateEvent (io.discloader.discloader.common.event.message.MessageCreateEvent)2 WebSocketFrame (com.neovisionaries.ws.client.WebSocketFrame)1 Command (io.discloader.discloader.client.command.Command)1 DLOptions (io.discloader.discloader.common.DLOptions)1 DiscLoader (io.discloader.discloader.common.DiscLoader)1 ShardManager (io.discloader.discloader.common.ShardManager)1 EventListenerAdapter (io.discloader.discloader.common.event.EventListenerAdapter)1 RawEvent (io.discloader.discloader.common.event.RawEvent)1 ReadyEvent (io.discloader.discloader.common.event.ReadyEvent)1 GroupMessageCreateEvent (io.discloader.discloader.common.event.message.GroupMessageCreateEvent)1 PrivateMessageCreateEvent (io.discloader.discloader.common.event.message.PrivateMessageCreateEvent)1 ShardLaunchedEvent (io.discloader.discloader.common.event.sharding.ShardLaunchedEvent)1 ShardingListenerAdapter (io.discloader.discloader.common.event.sharding.ShardingListenerAdapter)1 ITextChannel (io.discloader.discloader.entity.channel.ITextChannel)1 IMessage (io.discloader.discloader.entity.message.IMessage)1 MessageJSON (io.discloader.discloader.network.json.MessageJSON)1 File (java.io.File)1