Ejemplo n.º 1
0
        public async Task LoudenPlayer(string discordUsername)
        {
            if (!(await InstanceCheck() && await OperatorCheck(Context.Message.Author.Id)))
            {
                return;
            }

            var matchedUsers = Context.Guild.Users.Where(x => x.Username.Equals(discordUsername) || x.Nickname.Equals(discordUsername));

            if (matchedUsers.Count() == 0)
            {
                await ReplyAsync("There is no user matching the Discord nickname " + discordUsername + ".");

                return;
            }

            if (matchedUsers.Count() > 1)
            {
                await ReplyAsync("Two or more users have the same matching Discord nickname. This command cannot continue.");

                return;
            }

            Discord.WebSocket.SocketGuildUser rightUser = matchedUsers.First();
            // Add the user to any mentionable rank roles.
            await Bot.Instance.LoudenUserAndAddRoles(rightUser.Id);

            await ReplyAsync($"Discord user {rightUser.Username} is now set to loud.");
        }
Ejemplo n.º 2
0
        public async Task ResetUser(string discordUsername)
        {
            if (!(await InstanceCheck() && await OperatorCheck(Context.Message.Author.Id)))
            {
                return;
            }

            DiscordGuild contextGuild = Bot.Instance.guilds.byID[Context.Guild.Id];

            Discord.WebSocket.SocketGuildUser target = contextGuild.GetSingleUser(discordUsername);

            if (target == null)
            {
                await ReplyAsync("The provided ID does not match any actual user.");

                return;
            }
            else
            {
                await ReplyAsync($"Erasing all roles and ranks from the user {target.Username} from all guilds. ");

                foreach (var guild in Bot.Instance.guilds.guildList)
                {
                    if (guild.IsGuildMember(target.Id))
                    {
                        await guild.RemoveAllRankRoles(target);
                    }
                }

                await Bot.Instance._data.RemoveFromDatabases(target.Id);
            }
        }
Ejemplo n.º 3
0
        public async Task TrackUser(string discordUsername, string nick)
        {
            if (!(await InstanceCheck() && await OperatorCheck(Context.Message.Author.Id)))
            {
                return;
            }

            DiscordGuild guild        = Bot.Instance.guilds.byID[Context.Guild.Id];
            var          matchedUsers = guild.GetAllUsers(discordUsername);

            if (matchedUsers.Count() == 0)
            {
                await ReplyAsync("There is no user matching the Discord nickname " + discordUsername + ".");

                return;
            }

            if (matchedUsers.Count() > 1)
            {
                await ReplyAsync("Two or more users have the same matching Discord nickname. This command cannot continue.");

                return;
            }

            Discord.WebSocket.SocketGuildUser rightUser = matchedUsers.First();

            if (rightUser != null)
            {
                // We do not await this one, no need -- it should respond on its own time.
                _ = Bot.Instance.TrackUser(guild, rightUser.Id, nick, Context.Message.Channel.Name);
            }
        }
Ejemplo n.º 4
0
        public async Task ShushPlayer(string discordUsername)
        {
            if (!(await InstanceCheck() && await OperatorCheck(Context.Message.Author.Id)))
            {
                return;
            }

            var matchedUsers = Context.Guild.Users.Where(x => x.Username.Equals(discordUsername) || x.Nickname.Equals(discordUsername));

            if (matchedUsers.Count() == 0)
            {
                await ReplyAsync("There is no user matching the Discord nickname " + discordUsername + ".");

                return;
            }

            if (matchedUsers.Count() > 1)
            {
                await ReplyAsync("Two or more users have the same matching Discord nickname. This command cannot continue.");

                return;
            }

            Discord.WebSocket.SocketGuildUser rightUser = matchedUsers.First();
            await Bot.Instance.QuietenUserAndTakeRoles(rightUser.Id);

            await ReplyAsync($"Discord user {rightUser} is now shushed and won't be pinged.");
        }
Ejemplo n.º 5
0
        public async Task UpdateUser(string discordUsername)
        {
            if (!(await InstanceCheck() && await OperatorCheck(Context.Message.Author.Id)))
            {
                return;
            }

            DiscordGuild contextGuild = Bot.Instance.guilds.byID[Context.Guild.Id];

            Discord.WebSocket.SocketGuildUser target = contextGuild.GetSingleUser(discordUsername);

            if (target == null)
            {
                await ReplyAsync("The provided ID does not match any actual user.");

                return;
            }

            try
            {
                if (!await Bot.Instance._data.UserTracked(target.Id))
                {
                    await ReplyAsync($"User {target.Username} not tracked.");

                    return;
                }

                bool ret = await Bot.Instance.UpdateOne(target.Id);

                if (ret)
                {
                    await ReplyAsync($"User {target.Username} updated.");

                    // Print user's rank too.
                    Rank r = await Bot.Instance._data.QueryRank(target.Id);

                    if (r.Digits())
                    {
                        await ReplyAsync($"We see {target.Username}'s rank as {r.FullPrint()}");
                    }
                    else
                    {
                        await ReplyAsync($"We see {target.Username}'s rank as {r.CompactFullPrint()}");
                    }
                }
                else
                {
                    await ReplyAsync("Error during rank update (ret is false).");

                    return;
                }
            }
            catch (RankParsingException)
            {
                await ReplyAsync("Error during rank update (RankParsingException).");

                return;
            }
        }
Ejemplo n.º 6
0
 public static int GetAccessLevel(Discord.WebSocket.SocketGuildUser user)
 {
     foreach (KeyValuePair <int, List <ulong> > kvp in AccessLevelDiscordRoles)
     {
         if (user.Roles.Where(x => kvp.Value.Contains(x.Id)).FirstOrDefault() != default)
         {
             return(kvp.Key);
         }
     }
     return(0);
 }
Ejemplo n.º 7
0
        public async Task Manualrank(string discordUsername, string spectralRankName)
        {
            if (!(await InstanceCheck() && await OperatorCheck(Context.Message.Author.Id)))
            {
                return;
            }

            // match user from username

            DiscordGuild guild        = Bot.Instance.guilds.byID[Context.Guild.Id];
            var          matchedUsers = guild.GetAllUsers(discordUsername);

            if (matchedUsers.Count() == 0)
            {
                await ReplyAsync("There is no user matching the Discord nickname " + discordUsername + ".");

                return;
            }

            if (matchedUsers.Count() > 1)
            {
                await ReplyAsync("Two or more users have the same matching Discord nickname. This command cannot continue.");

                return;
            }

            Discord.WebSocket.SocketGuildUser rightUser = matchedUsers.First();

            // parse rank string
            Rank r = Ranking.FindRankFromSpectral(spectralRankName);

            if (r.met == Metal.Undefined)
            {
                await ReplyAsync("The inserted rank was not parsed correctly. Remember to put in the spectral name of the rank, such as D or P3.");

                return;
            }

            await ReplyAsync("Setting rank manually for the user " + discordUsername + " to rank " + r.FullPrint());
            await ReplyAsync("Keep in mind that the bot may update your rank later using new data from the R6Tab server.");

            await Bot.Instance.UpdateRoles(rightUser.Id, r);
        }
Ejemplo n.º 8
0
 private async Task Client_UserJoined(Discord.WebSocket.SocketGuildUser arg)
 {
     await UpdateGuildUserCountAsync(arg.Guild.Id);
 }
Ejemplo n.º 9
0
 public static string DisplayName(this Discord.WebSocket.SocketGuildUser user)
 {
     return(user.Nickname ?? user.Username);
 }
        public async Task KickMe()
        {
            Discord.WebSocket.SocketGuildUser Użytkownik = Context.Guild.GetUser(Context.User.Id);

            await Użytkownik.KickAsync();
        }
        private async System.Threading.Tasks.Task Client_GuildMemberUpdated(Cacheable <Discord.WebSocket.SocketGuildUser, ulong> cached, Discord.WebSocket.SocketGuildUser arg2)
        {
            if (!cached.HasValue)
            {
                return;
            }
            var arg1         = cached.Value;
            var priorRoles   = arg1?.Roles.Select(x => x.Id).ToList() ?? new List <ulong>();
            var currentRoles = arg2?.Roles.Select(x => x.Id).ToList() ?? new List <ulong>();

            var removedRoles = priorRoles.Where(x => currentRoles.Contains(x) == false);
            var addedRoles   = currentRoles.Where(x => priorRoles.Contains(x) == false);

            var bUser = Program.GetUser(arg2 ?? arg1);

            foreach (var role in removedRoles)
            {
                perform(bUser, arg2.Guild.Id, "RoleRemoved", role);
            }
            foreach (var role in addedRoles)
            {
                perform(bUser, arg2.Guild.Id, "RoleAdded", role);
            }
        }
 private async System.Threading.Tasks.Task Client_UserJoined(Discord.WebSocket.SocketGuildUser arg)
 {
     perform(Program.GetUser(arg), arg.Guild.Id, "UserJoined", null);
 }