Exemplo n.º 1
0
 public static async Task SendChannel(IDiscordMessageChannel channel, IDiscordEmbed message)
 {
     if (channel.Guild.CurrentUser.HasPermissions(channel, DiscordGuildPermission.SendMessages))
     {
         if (CanSendNotification(channel.Guild.Id, DatabaseEntityType.GUILD, DatabaseSettingId.CHANNELMESSAGE))
         {
             await message.SendToChannel(channel);
         }
     }
 }
Exemplo n.º 2
0
 public static async Task SendChannel(IDiscordMessageChannel channel, string message)
 {
     if ((await channel.Guild.GetCurrentUserAsync()).HasPermissions(channel, DiscordGuildPermission.SendMessages))
     {
         if (CanSendNotification(channel.Guild.Id, DatabaseSettingId.CHANNELMESSAGE))
         {
             await channel.QueueMessageAsync(message);
         }
     }
 }
Exemplo n.º 3
0
        public void Start(IDiscordMessageChannel channel, TimeSpan span)
        {
            Task.Run(async() =>
            {
                await Task.Delay((int)span.TotalMilliseconds);

                await CreateReminderEmbed(Text)
                .QueueToChannel(channel);

                parent.RemoveReminder(ReminderId);
            }, cancellationToken.Token);
        }
Exemplo n.º 4
0
        public async Task AddCurrencyAsync(int amount, IDiscordMessageChannel channel = null, User fromUser = null)
        {
            if (Banned)
            {
                return;
            }

            Currency += amount;

            if (channel != null)
            {
                await AchievementManager.Instance.CallTransactionMadeEventAsync(channel, this, fromUser, Currency);
            }
        }
Exemplo n.º 5
0
        public async Task RunTask(IDiscordMessageChannel channel)
        {
            await Task.Delay((int)Length.TotalMilliseconds);

            cancellationToken.Token.ThrowIfCancellationRequested();

            CreateReminderEmbed(Text)
            .QueueToChannel(channel);

            if (RepeatReminder)
            {
                parent.CreateNewReminder(channel, Text, Length, RepeatReminder);
            }
            parent.RemoveReminder(ReminderId);
        }
Exemplo n.º 6
0
        public int CreateNewReminder(IDiscordMessageChannel channel, string text, TimeSpan at)
        {
            int?id = GetRandomKey();

            if (id == null)
            {
                return(-1);
            }

            ReminderInstance reminder = new ReminderInstance(id.GetValueOrDefault(), this, text);

            reminder.Start(channel, at);

            instances.Add(id ?? 0, reminder);

            return(id.GetValueOrDefault());
        }
Exemplo n.º 7
0
        public async Task <string> Print(int currentValue, IDiscordMessageChannel c)
        {
            string output = "";

            IDiscordUser u = await c.Guild.GetUserAsync(Bot.Instance.CurrentUser.Id);

            if (!u.HasPermissions(c, DiscordGuildPermission.UseExternalEmojis))
            {
                return("");
            }

            int iteration        = MaxValue / Width;
            int currentIteration = iteration;

            for (int i = 0; i < Width; i++)
            {
                output           += (currentValue >= currentIteration) ? ValueOn.GetAppropriateSection(0, Width - 1, i) : ValueOff.GetAppropriateSection(0, Width - 1, i);
                currentIteration += iteration;
            }

            return(output);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Unlocks the achievement and if not yet added to the database, It'll add it to the database.
        /// </summary>
        /// <param name="context">sql context</param>
        /// <param name="id">user id</param>
        /// <param name="r">rank set to (optional)</param>
        /// <returns></returns>
        internal async Task UnlockAsync(MikiContext context, IDiscordMessageChannel channel, IDiscordUser user, int r = 0)
        {
            long userid = user.Id.ToDbLong();

            Achievement a = await context.Achievements.FindAsync(userid, ParentName);

            if (a != null || r != 0)
            {
                if (a.Rank == r - 1)
                {
                    a.Rank += 1;
                    await Notification.SendAchievement(this, channel, user);
                }
            }
            else
            {
                context.Achievements.Add(new Achievement()
                {
                    Id = userid, Name = ParentName, Rank = 0
                });
                await Notification.SendAchievement(this, channel, user);
            }
            await context.SaveChangesAsync();
        }
Exemplo n.º 9
0
        public async Task CallTransactionMadeEventAsync(IDiscordMessageChannel m, User receiver, User giver, int amount)
        {
            try
            {
                TransactionPacket p = new TransactionPacket();
                p.discordChannel = m;
                p.discordUser    = new RuntimeUser(Bot.instance.Client.GetUser(receiver.Id.FromDbLong()));

                if (giver != null)
                {
                    p.giver = giver;
                }

                p.receiver = receiver;

                p.amount = amount;

                await OnTransaction?.Invoke(p);
            }
            catch (Exception e)
            {
                Log.WarningAt("achievement check failed", e.ToString());
            }
        }
Exemplo n.º 10
0
 public async Task QueueToChannel(IDiscordMessageChannel channel)
 {
     Task.Run(async() => await SendToChannel(channel));
 }
Exemplo n.º 11
0
        public async Task CallAchievementUnlockEventAsync(BaseAchievement achievement, IDiscordUser user, IDiscordMessageChannel channel)
        {
            if (achievement as AchievementAchievement != null)
            {
                return;
            }

            long id = user.Id.ToDbLong();


            using (var context = new MikiContext())
            {
                int achievementCount = await context.Achievements
                                       .AsNoTracking()
                                       .Where(q => q.Id == id)
                                       .CountAsync();

                AchievementPacket p = new AchievementPacket()
                {
                    discordUser    = user,
                    discordChannel = channel,
                    achievement    = achievement,
                    count          = achievementCount
                };

                await OnAchievementUnlocked?.Invoke(p);
            }
        }
Exemplo n.º 12
0
        public async Task CallAchievementUnlockEventAsync(BaseAchievement achievement, IDiscordUser user, IDiscordMessageChannel channel)
        {
            if (achievement as AchievementAchievement != null)
            {
                return;
            }

            using (var context = new MikiContext())
            {
                long id = user.Id.ToDbLong();

                List <Achievement> achs = context.Achievements.Where(q => q.Id == id).ToList();
                int achievementCount    = achs.Sum(x => x.Rank + 1);

                AchievementPacket p = new AchievementPacket()
                {
                    discordUser    = user,
                    discordChannel = channel,
                    achievement    = achievement,
                    count          = achievementCount
                };

                await OnAchievementUnlocked?.Invoke(p);
            }
        }
Exemplo n.º 13
0
 public void Start(IDiscordMessageChannel channel)
 {
     Task.Run(() => RunTask(channel), cancellationToken.Token);
 }
Exemplo n.º 14
0
 public async Task <IDiscordMessage> SendToChannel(IDiscordMessageChannel channel)
 {
     return(await SendToChannel(channel.Id));
 }
Exemplo n.º 15
0
 public Task <IDiscordMessage> SendToChannel(IDiscordMessageChannel channel)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 16
0
 public static async Task SendAchievement(AchievementDataContainer d, int rank, IDiscordMessageChannel channel, IDiscordUser user)
 {
     await SendAchievement(d.Achievements[rank], channel, user);
 }
Exemplo n.º 17
0
 public static Locale GetLocale(this IDiscordMessageChannel c) => new Locale(c.Id);
Exemplo n.º 18
0
 public static Locale GetLocale(this IDiscordMessageChannel c) => Locale.GetEntity(c.Id);
Exemplo n.º 19
0
 public static void SendAchievement(AchievementDataContainer d, int rank, IDiscordMessageChannel channel, IDiscordUser user)
 => SendAchievement(d.Achievements[rank], channel, user);