Exemplo n.º 1
0
        public async Task SlotMachineSettingsAsync([Summary("typ nastaw(info - wyświetla informacje)")] SlotMachineSetting setting = SlotMachineSetting.Info, [Summary("wartość nastawy")] string value = "info")
        {
            if (setting == SlotMachineSetting.Info)
            {
                await ReplyAsync("", false, $"{_fun.GetSlotMachineInfo()}".ToEmbedMessage(EMType.Info).Build());

                return;
            }

            using (var db = new Database.UserContext(Config))
            {
                var botuser = await db.GetUserOrCreateAsync(Context.User.Id);

                if (!botuser.ApplySlotMachineSetting(setting, value))
                {
                    await ReplyAsync("", embed : $"Podano niewłaściwą wartość parametru!".ToEmbedMessage(EMType.Error).Build());

                    return;
                }

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}", "users" });
            }

            await ReplyAsync("", embed : $"{Context.User.Mention} zmienił nastawy automatu.".ToEmbedMessage(EMType.Success).Build());
        }
Exemplo n.º 2
0
        public static bool ApplySlotMachineSetting(this User user, SlotMachineSetting type, string value)
        {
            try
            {
                switch (type)
                {
                case SlotMachineSetting.Beat:
                    var bt = (SlotMachineBeat)Enum.Parse(typeof(SlotMachineBeat), $"b{value}");
                    user.SMConfig.Beat = bt;
                    break;

                case SlotMachineSetting.Rows:
                    var rw = (SlotMachineSelectedRows)Enum.Parse(typeof(SlotMachineSelectedRows), $"r{value}");
                    user.SMConfig.Rows = rw;
                    break;

                case SlotMachineSetting.Multiplier:
                    var mt = (SlotMachineBeatMultiplier)Enum.Parse(typeof(SlotMachineBeatMultiplier), $"x{value}");
                    user.SMConfig.Multiplier = mt;
                    break;

                default:
                    return(false);
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }