Exemple #1
0
            public async Task WhoIs(ulong userId)
            {
                if (Context.Message.Channel is SocketGuildChannel guildChannel)
                {
                    //check if the user, which has written the message, has admin rights or is server owner
                    if (AdminModule.IsAuthorized(GeneralModule.GetGuildUserFromGuild(Context.Message.Author as SocketUser, guildChannel.Guild)))
                    {
                        await Context.Message.Channel.SendMessageAsync($"{Context.Message.Author.Username}, you dont have the permissions to do this!");

                        return;
                    }
                    if (Program.MyGuild.Users.ToList().Find(u => u.Id == userId) == null)
                    {
                        await Context.Message.Channel.SendMessageAsync("User couldn't be found.");

                        return;
                    }
                    //user has admin rights
                    await Context.Message.Channel.SendMessageAsync($"{userId} => {Program.MyGuild.Users.ToList().Find(u => u.Id == userId)}");
                }
                else
                {
                    await Context.Message.Channel.SendMessageAsync("This command only works on a guild.");
                }
            }
Exemple #2
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.");
                }
            }
Exemple #3
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.");
                }
            }
Exemple #4
0
 public async Task ChangePrefix(char prefix)
 {
     //try casting to guild channel
     if (Context.Message.Channel is SocketGuildChannel guildChannel)
     {
         //check if this user is an admin of the specific guild
         SocketGuildUser user = guildChannel.Guild.Users.ToList().Find(u => u.Id == Context.Message.Author.Id);
         if (AdminModule.IsAuthorized(user))
         {
             CommandHandlerService.IdPrefixCollection[guildChannel.Guild.Id] = prefix;
             File.WriteAllText("meta/prefix.json", JsonConvert.SerializeObject(CommandHandlerService.IdPrefixCollection));
             await Context.Message.Channel.SendMessageAsync($"Now the new prefix is \"{prefix}\"");
         }
         else
         {
             await Context.Message.Channel.SendMessageAsync("You have no permission.");
         }
     }
     else
     {
         //channel isn't a guild channel
         await Context.Message.Channel.SendMessageAsync("This command has no effect here. Try using it on a guild.");
     }
 }