Beispiel #1
0
        private async Task NotifySubscriber(TuckContext context, Subscription subscription)
        {
            var channel = Context.Client.GetChannel(subscription.ChannelId) as ISocketMessageChannel;
            var message = await channel.SendMessageAsync(string.Format(
                                                             "{0}World buff list has been updated. ({1})",
                                                             // SubscriberAlert can never be null here either.. So fallback is just to cast to int(64)
                                                             MentionUtils.MentionRole(subscription.SubscriberAlert ?? 0) + ": ",
                                                             // CultureInfo param should be refactored to EU/NA/etc when multi-realm support is added.
                                                             DateTime.Now.ToString("HH:mm", new System.Globalization.CultureInfo("fr-FR"))
                                                             ));

            // If a previous alert exists, delete it.
            ulong lastAlert = subscription.LastAlert ?? 0;

            if (lastAlert != 0)
            {
                var lastMsg = await channel.GetMessageAsync(lastAlert);

                if (lastMsg != null)
                {
                    await lastMsg.DeleteAsync();
                }
            }

            // Store the new message Id.
            subscription.LastAlert = message.Id;
            context.Update(subscription);
            await context.SaveChangesAsync();
        }
Beispiel #2
0
        private async Task PostMessage(TuckContext context, Subscription subscription, Embed embed)
        {
            var channel = Context.Client.GetChannel(subscription.ChannelId) as ISocketMessageChannel;
            var message = await channel.SendMessageAsync("", false, embed);

            subscription.LastMessage = message.Id;
            context.Update(subscription);
            await context.SaveChangesAsync();
        }
Beispiel #3
0
        private async Task RemoveAlert(TuckContext context, Subscription subscription)
        {
            if (subscription.SubscriberAlert == null)
            {
                await ReplyAsync("No alert is currently active.");

                return;
            }

            subscription.SubscriberAlert = null;
            context.Update(subscription);
            await context.SaveChangesAsync();
        }
Beispiel #4
0
        public async Task PostBuffOverview()
        {
            using (var context = new TuckContext()) {
                var subscription = context.Subscriptions.AsQueryable()
                                   .Where(s => s.GuildId == Context.Guild.Id)
                                   .FirstOrDefault();

                var embed = GetBuffPost(context, subscription?.TargetGuildId ?? Context.Guild.Id);
                var msg   = await ReplyAsync("", false, embed);

                if (subscription != null && Context.Channel.Id == subscription.ChannelId)
                {
                    subscription.LastMessage = msg.Id;
                    context.Update(subscription);
                    await context.SaveChangesAsync();
                }
            }
        }
Beispiel #5
0
        private async Task AddAlert(TuckContext context, Subscription subscription, ulong role)
        {
            if (subscription.SubscriberAlert != null)
            {
                await ReplyAsync(string.Format(
                                     "Replacing alerts for {0} with {1}.",
                                     MentionUtils.MentionRole(subscription.SubscriberAlert ?? 0),
                                     MentionUtils.MentionRole(role)
                                     ));
            }
            else
            {
                await ReplyAsync(string.Format(
                                     "Enabled alerts for {0}.",
                                     MentionUtils.MentionRole(role)
                                     ));
            }

            subscription.SubscriberAlert = role;
            context.Update(subscription);
            await context.SaveChangesAsync();
        }