コード例 #1
0
        private static string Warn(SocketUser user)
        {
            if (user.IsBot)
            {
                return("You cannot give a warning to a bot!");
            }

            if (((SocketGuildUser)user).GuildPermissions.Administrator)
            {
                return("You cannot warn an administrator!");
            }

            SocketGuildUser       userGuild   = (SocketGuildUser)user;
            UserAccountServerData userAccount =
                UserAccountsManager.GetAccount(userGuild).GetOrCreateServer(userGuild.Guild.Id);

            if (userAccount.IsAccountNotWarnable)
            {
                return($"A warning cannot be given to **{user}**. That person's account is set to not warnable.");
            }

            userAccount.Warnings++;
            UserAccountsManager.SaveAccounts();
            return($"A warning was given to **{user}**");
        }
コード例 #2
0
        /// <summary>
        /// Checks a user's warn status
        /// </summary>
        /// <param name="user"></param>
        public static void CheckUserWarnStatus(SocketGuildUser user)
        {
            if (user.IsBot)
            {
                return;
            }

            if (user.GuildPermissions.Administrator)
            {
                return;
            }

            UserAccountServerData userAccount = GetAccount(user).GetOrCreateServer(user.Guild.Id);
            ServerList            server      = ServerListsManager.GetServer(user.Guild);

            //Warnings needed for kick and ban are set to the same amount, and the user has enough warnings so just straight ban
            if (server.WarningsKickAmount == server.WarningsBanAmount &&
                userAccount.Warnings >= server.WarningsKickAmount)
            {
                user.BanUser((SocketUser)Global.BotUser, $"Banned for having {server.WarningsKickAmount} warnings.");
            }

            //Enough warnings for a kick
            else if (userAccount.Warnings == server.WarningsKickAmount)
            {
                user.KickUser((SocketUser)Global.BotUser, $"Kicked for having {server.WarningsKickAmount} warnings.");
            }

            //Enough warnings for a ban
            else if (userAccount.Warnings >= server.WarningsBanAmount)
            {
                user.BanUser((SocketUser)Global.BotUser, $"Banned for having {server.WarningsBanAmount} warnings.");
            }
        }
コード例 #3
0
ファイル: AccountUtils.cs プロジェクト: remmody/Pootis-Bot
        public async Task Profile(SocketGuildUser user)
        {
            //Check to see if the user requested to view the profile of is a bot
            if (user.IsBot)
            {
                await Context.Channel.SendMessageAsync("You can not get a profile of a bot!");

                return;
            }

            //This will get the user's main role
            IReadOnlyCollection <SocketRole> roles = user.Roles;
            List <SocketRole> sortedRoles          = roles.OrderByDescending(o => o.Position).ToList();
            SocketRole        userMainRole         = sortedRoles.First();

            //Get the user's account and server data relating to the user
            UserAccount           account       = UserAccountsManager.GetAccount(user);
            UserAccountServerData accountServer = account.GetOrCreateServer(Context.Guild.Id);
            EmbedBuilder          embed         = new EmbedBuilder();

            string warningText = "No :sunglasses:";

            if (!accountServer.IsAccountNotWarnable && !user.GuildPermissions.Administrator)
            {
                warningText = $"Yes\n**Warnings: ** {accountServer.Warnings}";
            }

            embed.WithCurrentTimestamp();
            embed.WithThumbnailUrl(user.GetAvatarUrl());
            embed.WithTitle(user.Username + "'s Profile");

            embed.AddField("Stats", $"**Level: ** {account.LevelNumber}\n**Xp: ** {account.Xp}\n", true);
            embed.AddField("Server",
                           $"**Points: **{accountServer.Points}\n**Warnable: **{warningText}\n**Main Role: **{userMainRole.Name}\n",
                           true);
            embed.AddField("Account", $"**Id: **{account.Id}\n**Creation Date: **{user.CreatedAt}");

            embed.WithColor(userMainRole.Color);

            embed.WithFooter(account.ProfileMsg, user.GetAvatarUrl());

            string description = "";

            if (user.Id == Global.BotOwner.Id)
            {
                description += $":crown: {Global.BotName} owner!\n";
            }

            if (HighLevelProfileMessageManager.GetHighLevelProfileMessage(user.Id) != null)
            {
                description += HighLevelProfileMessageManager.GetHighLevelProfileMessage(user.Id).Message;
            }

            embed.WithDescription(description);

            await Context.Channel.SendMessageAsync("", false, embed.Build());
        }
コード例 #4
0
		private static void HandleUserPointsLevel(UserAccountServerData account, ServerList server,
			SocketCommandContext context, DateTime now)
		{
			//Server points
			if (!(now.Subtract(account.LastServerPointsTime).TotalSeconds >=
			      server.PointsGiveCooldownTime)) return;

			LevelingSystem.GiveUserServerPoints((SocketGuildUser) context.User,
				(SocketTextChannel) context.Channel, server.PointGiveAmount);

			//No need to save since this variable has a JsonIgnore attribute
			account.LastServerPointsTime = now;
		}
コード例 #5
0
ファイル: AntiSpamService.cs プロジェクト: remmody/Pootis-Bot
        /// <summary>
        /// Checks how many users are mention in a single message, if it is higher then the threshold then remove it
        /// </summary>
        /// <param name="message">The message to check</param>
        /// <param name="guild">The guild of the message</param>
        /// <returns>Whether the user is allowed to do that action</returns>
        public bool CheckMentionUsers(SocketUserMessage message, SocketGuild guild)
        {
            SocketGuildUser user = (SocketGuildUser)message.Author;

            UserAccountServerData serverAccount =
                UserAccountsManager.GetAccount(user).GetOrCreateServer(guild.Id);

            if (serverAccount.IsAccountNotWarnable)
            {
                return(false);
            }

            //If it is the owner of the Discord server, ignore
            if (user.Id == guild.OwnerId)
            {
                return(false);
            }

            //If user is a admin, ignore
            if (user.GuildPermissions.Administrator)
            {
                return(false);
            }

            int guildMemberCount = guild.Users.Count;
            int mentionCount     = message.MentionedUsers.Count;

            int percentage = mentionCount / guildMemberCount * 100;

            if (percentage > ServerListsManager.GetServer(guild).AntiSpamSettings.MentionUsersPercentage)
            {
                return(false);
            }

            message.Channel.SendMessageAsync(
                $"Hey {message.Author.Mention}, listing all members of this Discord server is not allowed!")
            .GetAwaiter().GetResult();

            message.DeleteAsync().GetAwaiter().GetResult();

            serverAccount.Warnings++;

            UserAccountsManager.CheckUserWarnStatus(user);
            UserAccountsManager.SaveAccounts();

            return(true);
        }
コード例 #6
0
        private Task HandleMessage(SocketMessage messageParam)
        {
            try
            {
                //Check the message to make sure it isn't a bot or such and get the SocketUserMessage and context
                if (!CheckMessage(messageParam, out SocketUserMessage msg, out SocketCommandContext context))
                {
                    return(Task.CompletedTask);
                }

                ServerList  server = ServerListsManager.GetServer(context.Guild);
                UserAccount user   = UserAccountsManager.GetAccount((SocketGuildUser)context.User);

                //Checks the message with the anti spam services
                if (!CheckMessageSpam(msg, context, user))
                {
                    return(Task.CompletedTask);
                }

                //If the message is in a banned channel then ignore it
                if (server.BannedChannels.Contains(msg.Channel.Id))
                {
                    return(Task.CompletedTask);
                }

                //Handle the command
                if (HandleCommand(msg, context, server))
                {
                    return(Task.CompletedTask);
                }

                //Since it isn't a command we do level up stuff
                UserAccountServerData userServerData = UserAccountsManager
                                                       .GetAccount((SocketGuildUser)context.User).GetOrCreateServer(context.Guild.Id);
                DateTime now = DateTime.Now;

                HandleUserXpLevel(user, context, now);
                HandleUserPointsLevel(userServerData, server, context, now);
            }
            catch (Exception ex)
            {
                Logger.Error("An error occured while handling a command! {@Exception}", ex);
            }

            return(Task.CompletedTask);
        }
コード例 #7
0
        public async Task MuteUser(SocketGuildUser user = null)
        {
            //Check to see if the user is null
            if (user == null)
            {
                await Context.Channel.SendMessageAsync("You need to input a username of a user!");

                return;
            }

            //Make sure the user being muted isn't the owner of the guild, because that would be retarded.
            if (user.Id == Context.Guild.OwnerId)
            {
                await Context.Channel.SendMessageAsync(
                    "Excuse me, you are trying to mute... the owner? That is a terrible idea.");

                return;
            }

            //Yea, muting your self isn't normal either.
            if (user == Context.User)
            {
                await Context.Channel.SendMessageAsync(
                    "Are you trying to mute your self? I don't think that is normal.");

                return;
            }

            UserAccount           account       = UserAccountsManager.GetAccount(user);
            UserAccountServerData accountServer = account.GetOrCreateServer(Context.Guild.Id);

            accountServer.IsMuted = true;

            UserAccountsManager.SaveAccounts();

            if (accountServer.IsMuted)
            {
                await Context.Channel.SendMessageAsync($"**{user.Username}** is now muted.");
            }
            else
            {
                await Context.Channel.SendMessageAsync($"**{user.Username}** is now un-muted.");
            }
        }
コード例 #8
0
        private static string MakeNotWarnable(IEnumerable <SocketGuildUser> users)
        {
            List <SocketGuildUser> usersToChange = new List <SocketGuildUser>();

            foreach (SocketGuildUser user in users)
            {
                if (user.IsBot)
                {
                    return("You cannot change the warnable status of a bot!");
                }

                if (user.GuildPermissions.Administrator)
                {
                    return("You cannot change the warnable status of an administrator!");
                }

                if (UserAccountsManager.GetAccount(user).GetOrCreateServer(user.Guild.Id).IsAccountNotWarnable)
                {
                    return($"**{user.Username}** is already not warnable!");
                }

                usersToChange.Add(user);
            }

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < usersToChange.Count; i++)
            {
                UserAccountServerData userAccount =
                    UserAccountsManager.GetAccount(usersToChange[i]).GetOrCreateServer(usersToChange[i].Guild.Id);

                userAccount.IsAccountNotWarnable = true;
                userAccount.Warnings             = 0;

                sb.Append(i + 1 == usersToChange.Count ? usersToChange[i].Username : $"{usersToChange[i].Username}, ");
            }

            UserAccountsManager.SaveAccounts();

            return(usersToChange.Count == 1
                                ? $"**{sb}** was made not warnable."
                                : $"The accounts **{sb}** were all made not warnable.");
        }
コード例 #9
0
ファイル: AntiSpamService.cs プロジェクト: remmody/Pootis-Bot
        /// <summary>
        /// Checks if a given user is allowed to @mention a certain role, and warns them if not
        /// </summary>
        /// <param name="message">The message to check</param>
        /// <param name="user">The author of the message</param>
        /// <returns>Whether the user is allowed to do that action</returns>
        public bool CheckRoleMentions(SocketUserMessage message, SocketGuildUser user)
        {
            UserAccountServerData serverAccount =
                UserAccountsManager.GetAccount(user).GetOrCreateServer(user.Guild.Id);

            if (serverAccount.IsAccountNotWarnable)
            {
                return(false);
            }

            //If it is the owner of the Discord server, ignore
            if (user.Id == user.Guild.OwnerId)
            {
                return(false);
            }

            ServerList server = ServerListsManager.GetServer(user.Guild);

            //Go over each role a user has
            foreach (SocketRole role in user.Roles)
            {
                foreach (ServerRoleToRoleMention notToMentionRoles in server.RoleToRoleMentions.Where(notToMentionRoles =>
                                                                                                      role.Id == notToMentionRoles.RoleNotToMentionId))
                {
                    message.DeleteAsync();

                    if (serverAccount.RoleToRoleMentionWarnings >=
                        server.AntiSpamSettings.RoleToRoleMentionWarnings)
                    {
                        message.Channel.SendMessageAsync(
                            $"Hey {user.Mention}, you have been pinging the **{RoleUtils.GetGuildRole(user.Guild, notToMentionRoles.RoleId).Name}** role, which you are not allowed to ping!\nA warning has been added to your account, for info see your profile.");
                        serverAccount.Warnings++;
                        UserAccountsManager.SaveAccounts();
                    }

                    serverAccount.RoleToRoleMentionWarnings++;

                    return(true);
                }
            }

            return(false);
        }
コード例 #10
0
		private Task HandleMessage(SocketMessage messageParam)
		{
			try
			{
				//Check the message to make sure it isn't a bot or such and get the SocketUserMessage and context
				if (!CheckMessage(messageParam, out SocketUserMessage msg, out SocketCommandContext context))
					return Task.CompletedTask;

				ServerList server = ServerListsManager.GetServer(context.Guild);
				UserAccount user = UserAccountsManager.GetAccount((SocketGuildUser) context.User);

				//Checks the message with the anti spam services
				if (!CheckMessageSpam(msg, context, user))
					return Task.CompletedTask;

				//If the message is in a banned channel then ignore it
				if (server.BannedChannels.Contains(msg.Channel.Id)) return Task.CompletedTask;

				//Handle the command
				if (HandleCommand(msg, context, server)) return Task.CompletedTask;

				//Since it isn't a command we do level up stuff
				UserAccountServerData userServerData = UserAccountsManager
					.GetAccount((SocketGuildUser) context.User).GetOrCreateServer(context.Guild.Id);
				DateTime now = DateTime.Now;

				HandleUserXpLevel(user, context, now);
				HandleUserPointsLevel(userServerData, server, context, now);
			}
			catch (Exception ex)
			{
#if DEBUG
				Logger.Log(ex.ToString(), LogVerbosity.Error);
#else
				Logger.Log(ex.Message, LogVerbosity.Error);
#endif
			}

			return Task.CompletedTask;
		}
コード例 #11
0
        /// <summary>
        /// Gives a user server points, and gives them a role if they past a certain amount of points
        /// </summary>
        /// <param name="user"></param>
        /// <param name="channel"></param>
        /// <param name="amount"></param>
        public static async void GiveUserServerPoints(SocketGuildUser user, SocketTextChannel channel, uint amount)
        {
            UserAccountServerData userAccount = UserAccountsManager.GetAccount(user).GetOrCreateServer(user.Guild.Id);

            userAccount.Points += amount;

            UserAccountsManager.SaveAccounts();

            //Give the user a role if they have enough points for it.
            ServerList       server     = ServerListsManager.GetServer(user.Guild);
            ServerRolePoints serverRole =
                server.GetServerRolePoints(userAccount.Points);

            Logger.Debug("{@Username} now has {@Points} points on guild {@GuildId}", user.Username, userAccount.Points, user.Guild.Id);

            if (serverRole.PointsRequired == 0)
            {
                return;
            }
            await user.AddRoleAsync(RoleUtils.GetGuildRole(user.Guild, serverRole.RoleId));

            await channel.SendMessageAsync(
                $"Congrats {user.Mention}, you got {userAccount.Points} points and got the **{RoleUtils.GetGuildRole(user.Guild, serverRole.RoleId).Name}** role!");
        }