Ejemplo n.º 1
0
        public async Task AddSubscription(ulong guildId, ulong channelId, ulong targetId)
        {
            if (Context.User.Id == 103492791069327360)
            {
                using (var context = new TuckContext()) {
                    if (context.Subscriptions.AsQueryable().Where(s => s.GuildId == guildId && s.TargetGuildId == targetId).Any())
                    {
                        await ReplyAsync("A subscription already exists.");

                        return;
                    }

                    var subscription = new Subscription()
                    {
                        GuildId       = guildId,
                        ChannelId     = channelId,
                        TargetGuildId = targetId
                    };

                    await context.AddAsync(subscription);

                    await context.SaveChangesAsync();
                    await ReplyAsync("The subscription was added");
                }
            }
        }
Ejemplo n.º 2
0
        public async Task RegisterNinjaPop(BuffType type, DateTime time, [Remainder] string username)
        {
            if (time > DateTime.Now)
            {
                await ReplyAsync($"On my watch the time is already {DateTime.Now.ToString("HH:mm:ss")}. You can't add a ninja pop that didn't happen yet.");

                return;
            }

            using (var context = new TuckContext()) {
                var subscription = context.Subscriptions.AsQueryable()
                                   .Where(s => s.GuildId == Context.Guild.Id && s.TargetGuildId != s.GuildId)
                                   .Any();

                if (subscription)
                {
                    await ReplyAsync("You cannot add buffs if a subscription exists");

                    return;
                }

                var buff = new BuffInstance {
                    GuildId  = Context.Guild.Id,
                    UserId   = Context.User.Id,
                    Time     = time,
                    Type     = type,
                    Ninja    = true,
                    Username = username
                };

                // Saving the buff instance
                await context.AddAsync(buff);

                await context.SaveChangesAsync();

                try {
                    await Context.Message.AddReactionAsync(Emote.Parse(_icons[buff.Type]));
                } catch (Discord.Net.HttpException) {
                    // If custom emoji's returns an error, add a thumbs up instead.
                    await Context.Message.AddReactionAsync(new Emoji("👍"));
                }

                // Posting an update message in all subscribing channels
                await MakeNotification(context, buff.GuildId, GetBuffPost(context, buff.GuildId));
            }
        }
Ejemplo n.º 3
0
        public async Task AddSubscription(ulong guildId)
        {
            using (var context = new TuckContext()) {
                if (context.Subscriptions.AsQueryable().Where(s => s.GuildId == Context.Guild.Id).Any())
                {
                    await ReplyAsync("The subscription was **not** added. A subscription already exists. Do unsubscribe to change the server subscribe too.");

                    return;
                }

                var subscription = new Subscription()
                {
                    GuildId       = Context.Guild.Id,
                    ChannelId     = Context.Channel.Id,
                    TargetGuildId = guildId
                };

                await context.AddAsync(subscription);

                await context.SaveChangesAsync();
                await ReplyAsync("The subscription was added");
            }
        }
Ejemplo n.º 4
0
        public async Task RegisterBuff(BuffType type, DateTime time, [Remainder] string username)
        {
            if (time < DateTime.Now)
            {
                await ReplyAsync($"On my watch the time is already {DateTime.Now.ToString("HH:mm")}. You can't add buffs earlier than that.");

                return;
            }

            using (var context = new TuckContext()) {
                var subscription = context.Subscriptions.AsQueryable()
                                   .Where(s => s.GuildId == Context.Guild.Id && s.TargetGuildId != s.GuildId)
                                   .Any();

                if (subscription)
                {
                    await ReplyAsync("You cannot add buffs if a subscription exists");

                    return;
                }

                var buff = new BuffInstance {
                    GuildId  = Context.Guild.Id,
                    UserId   = Context.User.Id,
                    Time     = time,
                    Type     = type,
                    Username = username
                };

                if (_cooldown.ContainsKey(buff.Type))
                {
                    var from = buff.Time.AddHours(-_cooldown[buff.Type]);
                    var to   = buff.Time.AddHours(_cooldown[buff.Type]);

                    var overlaps = context.Buffs.AsQueryable()
                                   .Where(t => t.GuildId == Context.Guild.Id)
                                   .Where(t => t.Type == buff.Type)
                                   .Where(t => t.Time > from && t.Time < to)
                                   .OrderBy(t => t.Time)
                                   .ToList();

                    if (overlaps.Count > 0)
                    {
                        var warning = $"The buff you just added will clash with buffs already added:";
                        foreach (var overlap in overlaps)
                        {
                            warning += $"\n> {overlap.Time.ToString("HH:mm")} by {overlap.Username} (<@{overlap.UserId}>)";
                        }
                        warning += $"\n\n To remove the buff you added, write !wbuff remove {buff.Type} {buff.Time.ToString("HH:mm")}";

                        var channel = await Context.User.GetOrCreateDMChannelAsync();

                        await channel.SendMessageAsync(warning);
                    }
                }

                // Saving the buff instance
                await context.AddAsync(buff);

                await context.SaveChangesAsync();

                try {
                    await Context.Message.AddReactionAsync(Emote.Parse(_icons[buff.Type]));
                } catch (Discord.Net.HttpException) {
                    // If custom emoji's returns an error, add a thumbs up instead.
                    await Context.Message.AddReactionAsync(new Emoji("👍"));
                }

                // Posting an update message in all subscribing channels
                await MakeNotification(context, buff.GuildId, GetBuffPost(context, buff.GuildId));
            }
        }