Esempio n. 1
0
        public async Task AcceptEmote(params string[] emoteIDs)
        {
            List <string> SuccessfulEmotes = new List <string>();
            string        dir = FinalEmoteLocation.Substring(0, FinalEmoteLocation.Length - 1);
            EmoteRequest  er  = new EmoteRequest(null, "", false, "", false);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            foreach (string s in emoteIDs)
            {
                if (GlobalVars.EmoteRequests.TryGetValue(s, out er))
                {
                    SuccessfulEmotes.Add(er.RequestID);

                    if (GlobalVars.RequestMessage.TryGetValue(er.RequestID, out var msg))
                    {
                        await msg.DeleteAsync();

                        GlobalVars.RequestMessage.Remove(er.RequestID);
                    }
                    string sql = $"INSERT INTO Emotes (EmoteID, RequestedBy, EmoteTrigger, fExt, RequireTarget, OutputText, Nsfw) VALUES ('{er.RequestID}', {er.RequestedBy.Id}, '{er.Trigger}', '{er.FileExtension}', {(er.RequiresTarget ? 1 : 0)}, '{er.OutputText}', {(er.Nsfw ? 1 : 0)});";
                    DBControl.UpdateDB(sql);

                    File.Move(RequestLocation + er.FileName, FinalEmoteLocation + er.FileName);
                    GlobalVars.EmoteList.Add(er.RequestID, new ApprovedEmote(er.RequestID, er.FileExtension, er.Trigger, er.RequiresTarget, er.OutputText, er.Nsfw));
                    GlobalVars.EmoteRequests.Remove(er.RequestID);
                }
            }

            await Context.Channel.SendMessageAsync($"Emote(s) ID(s) accepted: ({string.Join(", ", SuccessfulEmotes)})");
        }
Esempio n. 2
0
        private async Task SendRequest(EmoteRequest er)
        {
            EmbedBuilder eb = new EmbedBuilder()
                              .WithTitle($"Emote request by: {er.RequestedBy.Username}#{er.RequestedBy.Discriminator}")
                              .WithAuthor(er.RequestedBy)
                              .WithColor(Color.Orange);

            eb.AddField("Request ID:", er.RequestID);
            eb.AddField("Desired trigger:", er.Trigger);
            eb.AddField("Require user target:", er.RequiresTarget);
            eb.AddField("Nsfw:", er.Nsfw);
            eb.AddField("Output text:", er.OutputText.ToLower().Contains("{author}") ? er.OutputText : "{author} " + er.OutputText);

            var    chan   = Context.Client.GetChannel(623205967462662154) as IMessageChannel;
            string fName  = RequestLocation + er.FileName;
            var    reqMsg = await chan.SendFileAsync(fName, null, false, eb.Build());

            if (GlobalVars.RequestMessage.ContainsKey(er.RequestID))
            {
                GlobalVars.RequestMessage.Remove(er.RequestID);
            }
            GlobalVars.RequestMessage.Add(er.RequestID, reqMsg);
        }
Esempio n. 3
0
        public async Task RequestEmote(string trigger, string url, bool RequiresTarget, [Remainder] string msg)
        {
            if (msg == "")
            {
                msg = $"is {trigger}";
            }
            EmoteRequest er       = new EmoteRequest(Context.Message.Author, trigger, RequiresTarget, msg, false);
            string       finalURL = "";

            string[] imgFileTypes = { ".jpg", ".jpeg", ".gif", ".png" };
            foreach (string s in imgFileTypes)
            {
                if (url.Substring(url.Length - s.Length, s.Length) == s)
                {
                    finalURL         = url;
                    er.FileExtension = s;
                }
            }
            if (finalURL == "")
            {
                finalURL = url.Contains("tenor") ? ImageLogger.GetTenorGIF(url) : url.Contains("gfycat") ? ImageLogger.GetGfyCatAsync(url) : "";
                foreach (string s in imgFileTypes)
                {
                    if (finalURL.Substring(finalURL.Length - s.Length, s.Length) == s)
                    {
                        er.FileExtension = s;
                    }
                }
            }

            if (finalURL != "")
            {
                string dir = RequestLocation.Substring(0, RequestLocation.Length - 1);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                using (var c = new WebClient())
                {
                    try
                    {
                        c.DownloadFile(finalURL, RequestLocation + er.FileName);
                    }
                    catch (Exception ex) { }
                    while (c.IsBusy)
                    {
                    }
                }

                GlobalVars.EmoteRequests.Add(er.RequestID, er);



                try
                {
                    await SendRequest(er);

                    var m = await Context.Channel.SendMessageAsync($"Emote requested, emote ID: {er.RequestID}");

                    GlobalVars.AddRandomTracker(m, 15);
                    var perms = Context.Guild.GetUser(Context.Client.CurrentUser.Id).GetPermissions(Context.Channel as IGuildChannel);
                    if (perms.ManageMessages)
                    {
                        try { await Context.Message.DeleteAsync(); }
                        catch { }
                    }
                }
                catch (Discord.Net.HttpException ex)
                {
                    if (ex.DiscordCode == 40005)
                    {
                        var m = await Context.Channel.SendMessageAsync($"{Context.User.Mention}, the filesize is too large (~{new FileInfo(RequestLocation + er.FileName).Length / 1048576}MB). Max filesize: 8MB\nPlease resize your image or use another.");

                        GlobalVars.AddRandomTracker(m, 15);
                        File.Delete(RequestLocation + er.FileName);
                        GlobalVars.EmoteRequests.Remove(er.RequestID);
                    }
                    await Program.Client_Log(new LogMessage(LogSeverity.Error, "Emote Request", ex.Message, ex));
                }
            }
            else
            {
                var m = await Context.Channel.SendMessageAsync("Could not get the download URL for this image.");

                GlobalVars.AddRandomTracker(m, 20);
            }
        }