示例#1
0
        private static Task[] DownloadGifFromJson(CustomGifData pack, Update u)
        {
            List <Task> downloadTasks = new List <Task>();

            if (!String.IsNullOrEmpty(pack.ArsonistWins))
            {
                downloadTasks.Add(DownloadGif(pack.ArsonistWins, u.Message.Chat));
            }
            if (!String.IsNullOrEmpty(pack.BurnToDeath))
            {
                downloadTasks.Add(DownloadGif(pack.BurnToDeath, u.Message.Chat));
            }
            if (!String.IsNullOrEmpty(pack.CultWins))
            {
                downloadTasks.Add(DownloadGif(pack.CultWins, u.Message.Chat));
            }
            if (!String.IsNullOrEmpty(pack.LoversWin))
            {
                downloadTasks.Add(DownloadGif(pack.LoversWin, u.Message.Chat));
            }
            if (!String.IsNullOrEmpty(pack.NoWinner))
            {
                downloadTasks.Add(DownloadGif(pack.NoWinner, u.Message.Chat));
            }
            if (!String.IsNullOrEmpty(pack.SerialKillerWins))
            {
                downloadTasks.Add(DownloadGif(pack.SerialKillerWins, u.Message.Chat));
            }
            if (!String.IsNullOrEmpty(pack.SKKilled))
            {
                downloadTasks.Add(DownloadGif(pack.SKKilled, u.Message.Chat));
            }
            if (!String.IsNullOrEmpty(pack.StartChaosGame))
            {
                downloadTasks.Add(DownloadGif(pack.StartChaosGame, u.Message.Chat));
            }
            if (!String.IsNullOrEmpty(pack.StartGame))
            {
                downloadTasks.Add(DownloadGif(pack.StartGame, u.Message.Chat));
            }
            if (!String.IsNullOrEmpty(pack.TannerWin))
            {
                downloadTasks.Add(DownloadGif(pack.TannerWin, u.Message.Chat));
            }
            if (!String.IsNullOrEmpty(pack.VillagerDieImage))
            {
                downloadTasks.Add(DownloadGif(pack.VillagerDieImage, u.Message.Chat));
            }
            if (!String.IsNullOrEmpty(pack.VillagersWin))
            {
                downloadTasks.Add(DownloadGif(pack.VillagersWin, u.Message.Chat));
            }
            if (!String.IsNullOrEmpty(pack.WolfWin))
            {
                downloadTasks.Add(DownloadGif(pack.WolfWin, u.Message.Chat));
            }
            if (!String.IsNullOrEmpty(pack.WolvesWin))
            {
                downloadTasks.Add(DownloadGif(pack.WolvesWin, u.Message.Chat));
            }
            return(downloadTasks.ToArray());
        }
示例#2
0
        public async Task <HttpResponseMessage> Post()
        {
            using (var db = new WWContext())
            {
                try
                {
                    var res = Request.Content.ReadAsStringAsync().Result;

                    var stripeEvent = EventUtility.ConstructEvent(res, Request.Headers.GetValues("Stripe-Signature").FirstOrDefault(), StipeSecret);

                    // Handle the event
                    if (stripeEvent.Type == Events.InvoicePaymentSucceeded)
                    {
                        var paymentIntent = stripeEvent.Data.Object as Invoice;
                        var userid        = int.Parse(paymentIntent.Number.Substring(0, paymentIntent.Number.IndexOf("-")));
                        var amount        = Convert.ToInt32(paymentIntent.Total / 100);
                        var p             = db.Players.FirstOrDefault(x => x.TelegramId == userid);
                        if (p != null)
                        {
                            if (p.DonationLevel == null)
                            {
                                p.DonationLevel = 0;
                            }
                            var oldLevel = p.DonationLevel;
                            p.DonationLevel += amount;
                            var level = p.DonationLevel ?? 0;
                            var badge = "";
                            if (level >= 100)
                            {
                                badge += " 🥇";
                            }
                            else if (level >= 50)
                            {
                                badge += " 🥈";
                            }
                            else if (level >= 10)
                            {
                                badge += " 🥉";
                            }
                            if (p.Founder ?? false)
                            {
                                badge += "💎";
                            }

                            await bot.SendTextMessageAsync(userid, $"Successfully received ${amount} from you! YAY!\nTotal Donated: ${level}\nCurrent Badge (ingame): {badge}");

                            //check to see how many people have purchased gif packs

                            if (level > 10 && oldLevel < 10)
                            {
                                p.GifPurchased = true;
                                CustomGifData data;
                                var           json = p.CustomGifSet;
                                if (String.IsNullOrEmpty(json))
                                {
                                    data = new CustomGifData();
                                }
                                else
                                {
                                    data = JsonConvert.DeserializeObject <CustomGifData>(json);
                                }
                                if (!data.HasPurchased)
                                {
                                    await bot.SendTextMessageAsync(userid,
                                                                   "Congratulations! You have unlocked Custom Gif Packs :)\nUse /customgif to build your pack, /submitgif to submit for approval");
                                }
                                data.HasPurchased = true;

                                json           = JsonConvert.SerializeObject(data);
                                p.CustomGifSet = json;
                            }
                            db.SaveChanges();
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid User ID"));
                        }
                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Unexpected Event Type"));
                    }
                }
                catch (StripeException e)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e.ToString()));
                }
            }
        }
示例#3
0
        public async Task <HttpResponseMessage> Post()
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            using (var db = new WWContext())
            {
                try
                {
                    var body   = Request.Content.ReadAsStringAsync().Result;
                    var header = Request.Headers.GetValues("Authorization").FirstOrDefault();
                    header = header.Replace("Signature ", "");
                    var check = body + XsollaProjectSecretKey;
                    check = SHA1HashStringForUTF8String(check);
                    if (check != header)
                    {
                        return(CreateError(Request, "INVALID_SIGNATURE"));
                    }

                    var obj = JsonConvert.DeserializeObject <XsollaEvent>(body);
                    switch (obj?.notification_type)
                    {
                    case "user_validation":
                        var  userId = obj?.user.id;
                        long id     = 0;
                        try
                        {
                            id = long.Parse(userId);
                        }
                        catch
                        {
                            return(CreateError(Request, "INVALID_USER"));
                        }
                        if (id == 0)
                        {
                            return(CreateError(Request, "INVALID_USER"));
                        }
                        if (!db.Players.Any(x => x.TelegramId == id))
                        {
                            return(CreateError(Request, "INVALID_USER"));
                        }
                        return(Request.CreateResponse(HttpStatusCode.OK));

                    case "payment":
                        var userid = long.Parse(obj?.user.id);
                        var amount = (int)obj?.purchase?.virtual_currency?.amount;
                        var p      = db.Players.FirstOrDefault(x => x.TelegramId == userid);
                        if (p != null)
                        {
                            if (p.DonationLevel == null)
                            {
                                p.DonationLevel = 0;
                            }
                            var oldLevel = p.DonationLevel;
                            p.DonationLevel += amount;
                            var level = p.DonationLevel ?? 0;
                            var badge = "";
                            if (level >= 100)
                            {
                                badge += " 🥇";
                            }
                            else if (level >= 50)
                            {
                                badge += " 🥈";
                            }
                            else if (level >= 10)
                            {
                                badge += " 🥉";
                            }
                            if (p.Founder ?? false)
                            {
                                badge += "💎";
                            }

                            await bot.SendTextMessageAsync(userid, $"Successfully received ${amount} from you! YAY!\nTotal Donated: ${level}\nCurrent Badge (ingame): {badge}");

                            //check to see how many people have purchased gif packs

                            if (level > 10 && oldLevel < 10)
                            {
                                p.GifPurchased = true;
                                CustomGifData data;
                                var           json = p.CustomGifSet;
                                if (String.IsNullOrEmpty(json))
                                {
                                    data = new CustomGifData();
                                }
                                else
                                {
                                    data = JsonConvert.DeserializeObject <CustomGifData>(json);
                                }
                                if (!data.HasPurchased)
                                {
                                    await bot.SendTextMessageAsync(userid,
                                                                   "Congratulations! You have unlocked Custom Gif Packs :)\nUse /customgif to build your pack, /submitgif to submit for approval");
                                }
                                data.HasPurchased = true;

                                json           = JsonConvert.SerializeObject(data);
                                p.CustomGifSet = json;
                            }
                            db.SaveChanges();
                        }
                        else
                        {
                            return(CreateError(Request, "INVALID_USER"));
                        }
                        return(Request.CreateResponse(HttpStatusCode.OK));

                    case "refund":
                        userid = long.Parse(obj?.user.id);
                        var reason = obj?.refund_details?.reason;
                        amount = (int)obj?.purchase?.total?.amount;
                        await bot.SendTextMessageAsync(userid, $"Your donation did not pass through Xsolla because of: {reason}. If you have any questions please go to @werewolfsupport.");

                        return(Request.CreateResponse(HttpStatusCode.OK));

                    default:
                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                }
                catch (AggregateException e)
                {
                    var x = e.InnerExceptions[0];
                    while (x.InnerException != null)
                    {
                        x = x.InnerException;
                    }
                    await bot.SendTextMessageAsync(LogGroupId, x.Message + "\n" + x.StackTrace);

                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, x));
                }
                catch (ApiRequestException e)
                {
                    var code = e.ErrorCode;
                    var x    = e.InnerException;
                    while (x?.InnerException != null)
                    {
                        x = x.InnerException;
                    }
                    await bot.SendTextMessageAsync(LogGroupId, x?.Message + "\n" + x?.StackTrace);

                    return(Request.CreateErrorResponse((HttpStatusCode)code, x));
                }
                catch (Exception e)
                {
                    while (e.InnerException != null)
                    {
                        e = e.InnerException;
                    }
                    await bot.SendTextMessageAsync(LogGroupId, e.Message + "\n" + e.StackTrace);

                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
                }
            }
        }
示例#4
0
        public static void SetCustomGifs(Update u, string[] args)
        {
#if BETA
            Bot.Send("Please use this command with @werewolfbot", u.Message.From.Id);
            return;
#endif
            //check player has access!
            using (var db = new WWContext())
            {
                var p    = db.Players.FirstOrDefault(x => x.TelegramId == u.Message.From.Id);
                var json = p?.CustomGifSet;
                if ((p?.DonationLevel ?? 0) < 10)
                {
                    Bot.Send("You have not unlocked a custom GIF pack.  Please use /donate", u.Message.From.Id);
                    return;
                }

                CustomGifData data;
                if (String.IsNullOrEmpty(json))
                {
                    data = new CustomGifData
                    {
                        HasPurchased = true
                    };
                    p.GifPurchased = true;
                    p.CustomGifSet = JsonConvert.SerializeObject(data);
                    db.SaveChanges();
                }

                else
                {
                    data = JsonConvert.DeserializeObject <CustomGifData>(json ?? "");
                }
                //if (!data.HasPurchased)
                //{
                //    Bot.Send("You have not unlocked a custom GIF pack.  Please use /donate", u.Message.From.Id);
                //    return;
                //}

                Bot.Api.SendTextMessageAsync(u.Message.From.Id,
                                             "Ready to build your custom gif pack? Great! Before we begin, a few notes you should be aware of:\n" +
                                             "• Your pack will be submitted for approval.  An admin will check it, and once approved, you can start using it in games\n" +
                                             "• NSFW packs will be marked NSFW, and only groups that allow them will use it.  Check with your group admin first.\n" +
                                             "• Gifs that will NOT be allowed:\n" +
                                             " - Gifs containing brutal images\n" +
                                             " - Gifs containing illegal content\n" +
                                             " - Others, at our discretion\n" +
                                             "• I will send you a description of the image, to which you will reply (to the message) with the gif you want to use\n" +
                                             "\n\n" +
                                             "PLEASE NOTE: Changing any gifs will automatically remove the approval for your pack, and an admin will need to approve it again\n" +
                                             "Let's begin! Select the situation you want to set a gif for",
                                             replyMarkup: GetGifMenu(data));

                var msg = "Current Approval Status:\n";
                switch (data.Approved)
                {
                case null:
                    msg += "Pending";
                    break;

                case true:
                    var by = db.Players.FirstOrDefault(x => x.TelegramId == data.ApprovedBy);
                    msg += "Approved By " + by.Name;
                    break;

                case false:
                    var dby = db.Players.FirstOrDefault(x => x.TelegramId == data.ApprovedBy);
                    msg += "Disapproved By " + dby.Name + " for: " + data.DenyReason;
                    break;
                }
                Bot.Send(msg, u.Message.From.Id);
            }
        }
示例#5
0
        public static InlineKeyboardMarkup GetGifMenu(CustomGifData d)
        {
            var m      = new Menu(2);
            var images = new[] { "Villager Eaten", "Lone Wolf Wins", "Wolf Pack Win", "Village Wins", "Tanner Wins", "Cult Wins", "Serial Killer Wins", "Lovers Win", "No Winner", "Normal Start", "Chaos Start", "SK Killed", "Arsonist Wins", "Burn to death" };

            foreach (var img in images)
            {
                var i = img;
                if (d != null)
                {
                    var gifchoice = i.Split(' ')[0];
                    var added     = false;
                    switch (gifchoice)
                    {
                    case "Villager":
                        added = d.VillagerDieImage != null;
                        break;

                    case "Lone":
                        added = d.WolfWin != null;
                        break;

                    case "Wolf":
                        added = d.WolvesWin != null;
                        break;

                    case "Village":
                        added = d.VillagersWin != null;
                        break;

                    case "Tanner":
                        added = d.TannerWin != null;
                        break;

                    case "Cult":
                        added = d.CultWins != null;
                        break;

                    case "Serial":
                        added = d.SerialKillerWins != null;
                        break;

                    case "Lovers":
                        added = d.LoversWin != null;
                        break;

                    case "No":
                        added = d.NoWinner != null;
                        break;

                    case "Normal":
                        added = d.StartGame != null;
                        break;

                    case "Chaos":
                        added = d.StartChaosGame != null;
                        break;

                    case "SK":
                        added = d.SKKilled != null;
                        break;

                    case "Arsonist":
                        added = d.ArsonistWins != null;
                        break;

                    case "Burn":
                        added = d.BurnToDeath != null;
                        break;
                    }
                    i += (added ? " ✅" : " 🚫");
                }
                else
                {
                    i += " 🚫";
                }
                m.Buttons.Add(new InlineKeyboardCallbackButton(i, "customgif|" + i));
            }
            m.Buttons.Add(new InlineKeyboardCallbackButton("Show Badge: " + (d.ShowBadge ? "✅" : "🚫"), "customgif|togglebadge"));
            m.Buttons.Add(new InlineKeyboardCallbackButton("❗️ RESET GIFS ❗️", "customgif|resetgifs"));
            m.Buttons.Add(new InlineKeyboardCallbackButton("Done for now", "cancel|cancel|cancel"));
            m.Buttons.Add(new InlineKeyboardCallbackButton("Submit for approval", "customgif|submit"));

            return(m.CreateMarkupFromMenu());
        }
示例#6
0
        public static void RequestGif(CallbackQuery q)
        {
            Bot.Api.DeleteMessageAsync(q.From.Id, q.Message.MessageId);
            var choice = q.Data.Split('|')[1].Split(' ')[0];

            if (choice == "submit")
            {
                using (var db = new WWContext())
                {
                    var p = db.Players.FirstOrDefault(x => x.TelegramId == q.From.Id);
                    if (p != null)
                    {
                        var json = p?.CustomGifSet;
                        var data = JsonConvert.DeserializeObject <CustomGifData>(json);
                        if (data.Approved != null)
                        {
                            Bot.Send($"Your current GIF pack has already been {(data.Approved == true ? "" : "dis")}approved! You can't submit it again without any changes!", q.From.Id, customMenu: GetGifMenu(data));
                            return;
                        }
                        if (new[] { data.CultWins, data.LoversWin, data.NoWinner, data.SerialKillerWins, data.SKKilled, data.StartChaosGame, data.StartGame, data.TannerWin, data.VillagerDieImage, data.VillagersWin, data.WolfWin, data.WolvesWin }.All(x => string.IsNullOrEmpty(x)))
                        {
                            Bot.Send($"Please set at least one GIF before you submit your pack!", q.From.Id, customMenu: GetGifMenu(data));
                            return;
                        }
                        data.Submitted = true;
                        p.CustomGifSet = JsonConvert.SerializeObject(data);
                        db.SaveChanges();
                    }
                }
                var menu = new Menu(2);
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Review", "reviewgifs|" + q.From.Id));
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Dismiss", $"dismiss|" + q.From.Id));
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Approved: SFW", "approvesfw|" + q.From.Id));
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Approved: NSFW", "approvensfw|" + q.From.Id));
                Bot.Send($"User {q.From.Id} - @{q.From.Username} - has submitted a gif pack for approval", Settings.AdminChatId, customMenu: menu.CreateMarkupFromMenu());
                Bot.Send("Your pack has been submitted for approval to the admins.  Please wait while we review.",
                         q.From.Id);
                return;
            }
            if (choice == "togglebadge")
            {
                using (var db = new WWContext())
                {
                    var p    = db.Players.FirstOrDefault(x => x.TelegramId == q.From.Id);
                    var json = p?.CustomGifSet;
                    var data = JsonConvert.DeserializeObject <CustomGifData>(json);
                    data.ShowBadge = !data.ShowBadge;
                    p.CustomGifSet = JsonConvert.SerializeObject(data);
                    db.SaveChanges();
                    Bot.Send($"Your badge will {(data.ShowBadge ? "" : "not ")}be shown.", q.From.Id, customMenu: GetGifMenu(data));
                    return;
                }
            }
            if (choice == "resetgifs")
            {
                var menu = new Menu();
                menu.Buttons.Add(new InlineKeyboardCallbackButton("❗️ CONFIRM RESET ❗️", "customgif|confirmreset"));
                menu.Buttons.Add(new InlineKeyboardCallbackButton("Cancel", "customgif|cancelreset"));
                Bot.Send("You are about to reset your custom GIF set! All your saved GIFs will be deleted! You can set them again, but you will not be able to restore your current GIFs. Are you sure you want to continue?", q.From.Id, customMenu: menu.CreateMarkupFromMenu());
                return;
            }
            if (choice == "confirmreset")
            {
                using (var db = new WWContext())
                {
                    var p    = db.Players.FirstOrDefault(x => x.TelegramId == q.From.Id);
                    var data = new CustomGifData
                    {
                        HasPurchased = true
                    };
                    p.CustomGifSet = JsonConvert.SerializeObject(data);
                    db.SaveChanges();
                    Bot.Send("Your custom GIFs have successfully been reset.", q.From.Id, customMenu: GetGifMenu(data));
                    return;
                }
            }
            if (choice == "cancelreset")
            {
                using (var db = new WWContext())
                {
                    var p    = db.Players.FirstOrDefault(x => x.TelegramId == q.From.Id);
                    var json = p?.CustomGifSet;
                    var data = JsonConvert.DeserializeObject <CustomGifData>(json);
                    Bot.Send($"You cancelled resetting your GIFs.", q.From.Id, customMenu: GetGifMenu(data));
                    return;
                }
            }
            Bot.Api.SendTextMessageAsync(q.From.Id,
                                         q.Data.Split('|')[1] + "\nOk, send me the GIF you want to use for this situation, as a reply\n" +
                                         "#" + choice,
                                         replyMarkup: new ForceReply()
            {
                Force = true
            });
        }