示例#1
0
            public async Task AddRankRole(int index, ulong roleId)
            {
                if (Context.Message.Channel is SocketGuildChannel guildChannel)
                {
                    //get user from guild
                    SocketGuildUser user = guildChannel.Guild.Users.ToList().Find(u => u.Id == Context.Message.Author.Id);
                    //check guild priviliges
                    if (!AdminModule.IsAuthorized(user))
                    {
                        await Context.Message.Channel.SendMessageAsync("You have no permission for this command.");

                        return;
                    }
                    ulong                   guildId = guildChannel.Guild.Id;
                    SocketGuild             guild   = guildChannel.Guild;
                    Dictionary <int, ulong> guildRankRoleCollection = new Dictionary <int, ulong>();
                    guildRankRoleCollection = RoleManagerService.RankRoleCollection[guildId];
                    if (index > 500)
                    {
                        await Context.Message.Channel.SendMessageAsync("Desired level is too high.");

                        return;
                    }
                    if (guild.Roles.ToList().Find(r => r.Id == roleId) == null)
                    {
                        await Context.Message.Channel.SendMessageAsync("There is no role with this id on this guild.");

                        return;
                    }
                    if (guildRankRoleCollection.Count >= 20)
                    {
                        await Context.Message.Channel.SendMessageAsync("You can't add anymore roles.");

                        return;
                    }
                    if (guildRankRoleCollection.Values.ToList().Contains(roleId))
                    {
                        await Context.Message.Channel.SendMessageAsync("You have already added this role.");

                        return;
                    }
                    if (!guildRankRoleCollection.ContainsKey(index))
                    {
                        guildRankRoleCollection.Add(index, roleId);
                    }
                    guildRankRoleCollection[index] = roleId;
                    RoleManagerService.RankRoleCollection[guildId] = guildRankRoleCollection;
                    RoleManagerService.SaveRankRoleCollection();
                    await Context.Message.Channel.SendMessageAsync($"{guild.Roles.ToList().Find(r => r.Id == roleId).Name} was added with Level {index}.");
                }
                else
                {
                    await Context.Message.Channel.SendMessageAsync("You can only perfom this command on a server.");
                }
            }
示例#2
0
            public async Task RemoveRankRole(int index)
            {
                if (Context.Message.Channel is SocketGuildChannel guildChannel)
                {
                    //check if user has admin priviliges
                    if (AdminModule.IsAuthorized(GeneralModule.GetGuildUserFromGuild(Context.Message.Author as SocketUser, guildChannel.Guild)))
                    {
                        await Context.Message.Channel.SendMessageAsync("You cant do this.");

                        return;
                    }
                    ulong                   guildId = guildChannel.Guild.Id;
                    SocketGuild             guild   = guildChannel.Guild;
                    Dictionary <int, ulong> guildRankRoleCollection = RoleManagerService.RankRoleCollection[guildId];
                    if (guildRankRoleCollection == null)
                    {
                        await Context.Message.Channel.SendMessageAsync("There are no roles to remove.");

                        return;
                    }
                    //if (guild.Roles.ToList().Find(r => r.Id == roleId) == null)
                    //{
                    //    await Context.Message.Channel.SendMessageAsync("This role dont exist on this server.");
                    //    return;
                    //}
                    //if (guildRankRoleCollection.Values.ToList().Contains(roleId))
                    //{
                    //    await Context.Message.Channel.SendMessageAsync("You cant remove this role, because it was never added.");
                    //    return;
                    //}
                    if (!guildRankRoleCollection.ContainsKey(index))
                    {
                        await Context.Message.Channel.SendMessageAsync("The current index is not in your role collection.");

                        return;
                    }
                    guildRankRoleCollection.Remove(index);
                    RoleManagerService.SaveRankRoleCollection();
                    await Context.Message.Channel.SendMessageAsync("Role successfully removed.");
                }
                else
                {
                    await Context.Message.Channel.SendMessageAsync("This is a server command only.");
                }
            }