Ejemplo n.º 1
0
        private async Task BlackWhite(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args)
        {
            string url  = string.IsNullOrWhiteSpace(args[0]) ? Handler.GetLastPictureURL((msg.Channel as SocketChannel)) : args[0];
            string path = null;

            if (!string.IsNullOrWhiteSpace(url)) //if getlastpicture returns nothing
            {
                path = await ImageProcess.DownloadImage(url);
            }

            if (path != null)
            {
                try
                {
                    ImageProcess.Resize(path);
                    ImageProcess.MakeBlackWhite(path);

                    await msg.Channel.SendFileAsync(path);

                    ImageProcess.DeleteImage(path);
                }catch (Exception e)
                {
                    BotLog.Debug(e.ToString());
                }
            }

            if (path == null)
            {
                await embedrep.Danger(msg, "Ugh", "There's no valid url to use!");
            }
        }
Ejemplo n.º 2
0
        private static Lua CreateState(SocketChannel chan)
        {
            try
            {
                Lua state = new Lua();
                state.DoFile("External/Lua/Init.lua");
                if (chan is IGuildChannel)
                {
                    IGuildChannel c = chan as IGuildChannel;
                    state.DoString(@"
                    ENV.CHANNEL_ID   = tonumber([[" + chan.Id.ToString() + @"]])
                    ENV.CHANNEL_NAME = [[" + c.Name + @"]]
                    ENV.GUILD_ID     = tonumber([[" + c.GuildId + @"]])
                    ENV.GUILD_NAME   = [[" + c.Guild.Name + @"]]
                ", "Startup");

                    _Client.Discord.UserJoined += async user =>
                    {
                        if (user.Guild == c.Guild)
                        {
                            state["USER"] = user as SocketUser;
                            Object[] returns = state.DoString(@"return event.fire('OnMemberAdded',USER)");
                            state["USER"] = null;
                            await _Client.Handler.EmbedReply.Send((chan as ISocketMessageChannel), "LuaEvent", returns[0].ToString());
                        }
                    };

                    _Client.Discord.UserLeft += async user =>
                    {
                        if (user.Guild == c.Guild)
                        {
                            state["USER"] = user as SocketUser;
                            Object[] returns = state.DoString(@"return event.fire('OnMemberRemoved',USER)");
                            state["USER"] = null;
                            await _Client.Handler.EmbedReply.Send((chan as ISocketMessageChannel), "LuaEvent", returns[0].ToString());
                        }
                    };
                }
                else
                {
                    IDMChannel c = chan as IDMChannel;
                    state.DoString(@"
                    ENV.CHANNEL_ID   = tonumber([[" + c.Id.ToString() + @"]])
                    ENV.CHANNEL_NAME = [[" + c.Name + @"]]
                ", "Startup");
                }

                _Client.Discord.MessageReceived += async msg =>
                {
                    if ((msg.Channel as SocketChannel) == chan && msg.Author.Id != _App.Id)
                    {
                        state["USER"]    = msg.Author;
                        state["MESSAGE"] = msg;
                        Object[] returns = state.DoString(@"return event.fire('OnMessageCreated',USER,MESSAGE)");
                        state["USER"]    = null;
                        state["MESSAGE"] = null;
                        await _Client.Handler.EmbedReply.Send((chan as ISocketMessageChannel), "LuaEvent", returns[0].ToString());
                    }
                };

                _Client.Discord.MessageDeleted += async(msg, c) =>
                {
                    IMessage mess = await msg.DownloadAsync();

                    if ((c as SocketChannel) == chan && mess.Author.Id != _App.Id)
                    {
                        state["MESSAGE"] = mess as SocketMessage;
                        state["USER"]    = mess.Author as SocketUser;
                        Object[] returns = state.DoString(@"return event.fire('OnMessageDeleted',USER,MESSAGE)");
                        state["USER"]    = null;
                        state["MESSAGE"] = null;
                        await _Client.Handler.EmbedReply.Send(c, "LuaEvent", returns[0].ToString());
                    }
                };

                _Client.Discord.MessageUpdated += async(cache, msg, c) =>
                {
                    if ((c as SocketChannel) == chan && msg.Author.Id != _App.Id)
                    {
                        state["USER"]    = msg.Author as SocketUser;
                        state["MESSAGE"] = msg as SocketMessage;
                        Object[] returns = state.DoString(@"return event.fire('OnMessageEdited',USER,MESSAGE)");
                        state["USER"]    = null;
                        state["MESSAGE"] = null;
                        await _Client.Handler.EmbedReply.Send(c, "LuaEvent", returns[0].ToString());
                    }
                };

                return(state);
            }catch (LuaException e)
            {
                BotLog.Debug(e.Message);
            }

            return(new Lua());
        }