コード例 #1
0
        public bool ToggleCurrencyGeneration(ulong gid, ulong cid)
        {
            bool enabled;

            using (var uow = _db.UnitOfWork)
            {
                var guildConfig = uow.GuildConfigs.ForId(gid, set => set.Include(gc => gc.GenerateCurrencyChannelIds));

                var toAdd = new GCChannelId()
                {
                    ChannelId = cid
                };
                if (!guildConfig.GenerateCurrencyChannelIds.Contains(toAdd))
                {
                    guildConfig.GenerateCurrencyChannelIds.Add(toAdd);
                    _generationChannels.Add(cid);
                    enabled = true;
                }
                else
                {
                    var toDelete = guildConfig.GenerateCurrencyChannelIds.FirstOrDefault(x => x.Equals(toAdd));
                    if (toDelete != null)
                    {
                        uow._context.Remove(toDelete);
                    }
                    _generationChannels.TryRemove(cid);
                    enabled = false;
                }
                uow.Complete();
            }
            return(enabled);
        }
コード例 #2
0
            public async Task GenCurrency()
            {
                var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(gc => gc.GenerateCurrencyChannelIds));

                var toAdd = new GCChannelId {
                    ChannelId = Context.Channel.Id
                };

                if (!gc.GenerateCurrencyChannelIds.Contains(toAdd))
                {
                    gc.GenerateCurrencyChannelIds.Add(toAdd);
                    await ReplyConfirmLocalized("curgen_enabled").ConfigureAwait(false);
                }
                else
                {
                    gc.GenerateCurrencyChannelIds.Remove(toAdd);
                    await ReplyConfirmLocalized("curgen_disabled").ConfigureAwait(false);
                }

                await uow.SaveChangesAsync(false);
            }
コード例 #3
0
            public async Task GenCurrency()
            {
                var channel = (ITextChannel)Context.Channel;

                bool enabled;

                using (var uow = _db.UnitOfWork)
                {
                    var guildConfig = uow.GuildConfigs.ForId(channel.Guild.Id, set => set.Include(gc => gc.GenerateCurrencyChannelIds));

                    var toAdd = new GCChannelId()
                    {
                        ChannelId = channel.Id
                    };
                    if (!guildConfig.GenerateCurrencyChannelIds.Contains(toAdd))
                    {
                        guildConfig.GenerateCurrencyChannelIds.Add(toAdd);
                        _service.GenerationChannels.Add(channel.Id);
                        enabled = true;
                    }
                    else
                    {
                        guildConfig.GenerateCurrencyChannelIds.Remove(toAdd);
                        _service.GenerationChannels.TryRemove(channel.Id);
                        enabled = false;
                    }
                    await uow.CompleteAsync().ConfigureAwait(false);
                }
                if (enabled)
                {
                    await ReplyConfirmLocalized("curgen_enabled").ConfigureAwait(false);
                }
                else
                {
                    await ReplyConfirmLocalized("curgen_disabled").ConfigureAwait(false);
                }
            }
コード例 #4
0
            public async Task GenCurrency(IUserMessage imsg)
            {
                var channel = (ITextChannel)imsg.Channel;

                bool enabled;

                using (var uow = DbHandler.UnitOfWork())
                {
                    var guildConfig = uow.GuildConfigs.For(channel.Id);

                    var toAdd = new GCChannelId()
                    {
                        ChannelId = channel.Id
                    };
                    if (!guildConfig.GenerateCurrencyChannelIds.Contains(toAdd))
                    {
                        guildConfig.GenerateCurrencyChannelIds.Add(toAdd);
                        generationChannels.Add(channel.Id);
                        enabled = true;
                    }
                    else
                    {
                        guildConfig.GenerateCurrencyChannelIds.Remove(toAdd);
                        generationChannels.TryRemove(channel.Id);
                        enabled = false;
                    }
                    await uow.CompleteAsync();
                }
                if (enabled)
                {
                    await channel.SendMessageAsync("`Currency generation enabled on this channel.`").ConfigureAwait(false);
                }
                else
                {
                    await channel.SendMessageAsync($"`Currency generation disabled on this channel.`").ConfigureAwait(false);
                }
            }
コード例 #5
0
            public async Task GenCurrency()
            {
                var channel = (ITextChannel)Context.Channel;

                bool enabled;

                using (var uow = DbHandler.UnitOfWork())
                {
                    var guildConfig = uow.GuildConfigs.For(channel.Id, set => set.Include(gc => gc.GenerateCurrencyChannelIds));

                    var toAdd = new GCChannelId()
                    {
                        ChannelId = channel.Id
                    };
                    if (!guildConfig.GenerateCurrencyChannelIds.Contains(toAdd))
                    {
                        guildConfig.GenerateCurrencyChannelIds.Add(toAdd);
                        generationChannels.Add(channel.Id);
                        enabled = true;
                    }
                    else
                    {
                        guildConfig.GenerateCurrencyChannelIds.Remove(toAdd);
                        generationChannels.TryRemove(channel.Id);
                        enabled = false;
                    }
                    await uow.CompleteAsync();
                }
                if (enabled)
                {
                    await channel.SendConfirmAsync("Currency generation enabled on this channel.").ConfigureAwait(false);
                }
                else
                {
                    await channel.SendConfirmAsync("Currency generation disabled on this channel.").ConfigureAwait(false);
                }
            }