Пример #1
0
        public async Task AddPermissionAsync(int methodID, string targetID, int permType, int allowType)
        {
            await Context.Guild.SyncGuildAsync().ConfigureAwait(false);

            if (!string.Equals(targetID, "everyone", StringComparison.InvariantCultureIgnoreCase))
            {
                var id = Convert.ToUInt64(targetID);

                switch ((PermType)permType)
                {
                case PermType.Role:
                    if (Context.Guild.GetRole(id) == null)
                    {
                        await ReplyAsync("Taková role neexistuje");

                        return;
                    }
                    break;

                case PermType.User:
                    if (await Context.Guild.GetUserFromGuildAsync(id) == null)
                    {
                        await ReplyAsync("Takový uživatel neexistuje.");

                        return;
                    }
                    break;

                case PermType.Everyone:
                    await ReplyAsync("Pro povolení všem použij klíčové slovo `everyone` jako identifikátor.");

                    return;
                }
            }
            else
            {
                permType = (int)PermType.Everyone;
            }

            try
            {
                ConfigRepository.AddPermission(Context.Guild, methodID, targetID, (PermType)permType, (AllowType)allowType);
                await ReplyAsync("Oprávnění bylo úspěšně přidáno.").ConfigureAwait(false);
            }
            catch (ArgumentException ex)
            {
                await ReplyAsync(ex.Message);
            }
        }