示例#1
0
 public static async Task SendAchievementAsync(BaseAchievement baseAchievement, IDiscordUser user)
 {
     SendAchievement(baseAchievement, await user.GetDMChannel(), user);
 }
示例#2
0
        public GamblingModule()
        {
            if (!Global.Config.IsMainBot)
            {
                lotteryId = taskScheduler.AddTask(0, (s) =>
                {
                    long size = (Global.RedisClient as StackExchangeCacheClient).Client.GetDatabase(0).ListLength(lotteryKey);

                    if (size == 0)
                    {
                        return;
                    }

                    string value = (Global.RedisClient as StackExchangeCacheClient).Client.GetDatabase(0).ListGetByIndex(lotteryKey, MikiRandom.Next(size));

                    ulong winnerId = ulong.Parse(value);
                    int wonAmount  = (int)Math.Round(size * 100 * 0.75);

                    IDiscordUser user = null;                     //Bot.Instance.ChatClient.GetUser(winnerId);

                    using (var context = new MikiContext())
                    {
                        long id          = winnerId.ToDbLong();
                        User profileUser = context.Users.Find(id);

                        if (user != null)
                        {
                            IDiscordChannel channel = user.GetDMChannel().Result;

                            EmbedBuilder embed = new EmbedBuilder()
                            {
                                Author = new EmbedAuthor()
                                {
                                    Name    = "Winner winner chicken dinner",
                                    IconUrl = user.GetAvatarUrl()
                                },
                                Description = $"Wow! You won the lottery and gained {wonAmount} mekos!"
                            };

                            profileUser.AddCurrencyAsync(wonAmount, channel);

                            embed.ToEmbed().QueueToChannel(channel);

                            context.SaveChanges();

                            Global.RedisClient.RemoveAsync(lotteryKey);
                            Global.RedisClient.UpsertAsync("lottery:winner", profileUser.Name ?? "unknown");
                            lotteryDict.ClearAsync();

                            var lotteryAchievement = AchievementManager.Instance.GetContainerById("lottery");

                            if (wonAmount > 100000)
                            {
                                lotteryAchievement.Achievements[0].UnlockAsync(channel, user, 0);
                            }

                            if (wonAmount > 10000000)
                            {
                                lotteryAchievement.Achievements[1].UnlockAsync(channel, user, 1);
                            }

                            if (wonAmount > 250000000)
                            {
                                lotteryAchievement.Achievements[2].UnlockAsync(channel, user, 1);
                            }
                        }
                    }
                }, "", new TimeSpan(0, 1, 0, 0), true);
            }
        }
示例#3
0
        public static async Task <IDiscordMessage> SendToUser(this DiscordEmbed embed, IDiscordUser user)
        {
            await Task.Yield();

            return(await(await user.GetDMChannel()).SendMessageAsync("", false, embed));
        }