Exemple #1
0
        public async Task RoleUpdated(SocketRole before, SocketRole after)
        {
            try
            {
                SocketGuild guild  = before.Guild;
                ServerList  server = ServerListsManager.GetServer(guild);

                IDMChannel dm = await guild.Owner.GetOrCreateDMChannelAsync();

                //Check all server role pings to make sure they are still mentionable
                List <ServerRoleToRoleMention> rolesToRemove = server.RoleToRoleMentions
                                                               .Where(roleToRole => roleToRole.RoleId == after.Id && !after.IsMentionable).ToList();
                foreach (ServerRoleToRoleMention roleToRemove in rolesToRemove)
                {
                    await dm.SendMessageAsync(
                        $"The **{after.Name}** role was changed to not mentionable so it was deleted from the **{RoleUtils.GetGuildRole(guild, roleToRemove.RoleNotToMentionId).Name}** => **{RoleUtils.GetGuildRole(guild, roleToRemove.RoleId).Name}** role to role ping list. ({guild.Name})");

                    server.RoleToRoleMentions.Remove(roleToRemove);
                    ServerListsManager.SaveServerList();

                    return;
                }
            }
            catch (Exception ex)
            {
                Logger.Error("An error occured while managing role updated event! {@Exception}", ex);
            }
        }
Exemple #2
0
        /// <summary>
        /// Checks all the bot's active auto voice channels
        /// </summary>
        /// <param name="server"></param>
        public static void CheckServerActiveVoiceChannels(ServerList server)
        {
            //Get all the active voice channels that have been deleted, or have no one in it
            List <ulong> autoVcChannelsToDelete = (from serverActiveAutoVoiceChannel in server.ActiveAutoVoiceChannels
                                                   let vcChannel = _client.GetGuild(server.GuildId).GetVoiceChannel(serverActiveAutoVoiceChannel)
                                                                   where vcChannel == null
                                                                   select serverActiveAutoVoiceChannel).ToList();

            foreach (ulong voiceChannel in autoVcChannelsToDelete)
            {
                server.ActiveAutoVoiceChannels.Remove(voiceChannel);
            }

            List <ulong> autoVcWithNoUsers = (from activeAutoVoiceChannel in server.ActiveAutoVoiceChannels
                                              let vcChannel = _client.GetGuild(server.GuildId).GetVoiceChannel(activeAutoVoiceChannel)
                                                              where vcChannel.Users.Count == 0
                                                              select activeAutoVoiceChannel).ToList();

            foreach (ulong autoVoiceChannel in autoVcWithNoUsers)
            {
                _client.GetGuild(server.GuildId).GetVoiceChannel(autoVoiceChannel).DeleteAsync();
                server.ActiveAutoVoiceChannels.Remove(autoVoiceChannel);
            }

            ServerListsManager.SaveServerList();
        }
        public async Task SetRoleToRoleMentionWarnings(int warnings)
        {
            ServerListsManager.GetServer(Context.Guild).AntiSpamSettings.RoleToRoleMentionWarnings = warnings;
            ServerListsManager.SaveServerList();

            await Context.Channel.SendMessageAsync($"The amount of role to role warnings will be {warnings}.");
        }
Exemple #4
0
        public async Task ChannelDestroyed(SocketChannel channel)
        {
            try
            {
                ServerList server = ServerListsManager.GetServer(((SocketGuildChannel)channel).Guild);

                //Check the server's welcome settings
                await BotCheckServerSettings.CheckServerWelcomeSettings(server);

                //Check the bot's auto voice channels
                BotCheckServerSettings.CheckServerVoiceChannels(server);
                BotCheckServerSettings.CheckServerActiveVoiceChannels(server);

                //Check the bot's rule message channel
                await BotCheckServerSettings.CheckServerRuleMessageChannel(server);
            }
            catch (Exception ex)
            {
#if DEBUG
                Logger.Log(ex.ToString(), LogVerbosity.Error);
#else
                Logger.Log(ex.Message, LogVerbosity.Error);
#endif
            }
        }
Exemple #5
0
        public async Task MessageDeleted(Cacheable <IMessage, ulong> cache, ISocketMessageChannel channel)
        {
            try
            {
                SocketGuild guild  = ((SocketGuildChannel)channel).Guild;
                ServerList  server = ServerListsManager.GetServer(guild);
                if (cache.Id == server.RuleMessageId)
                {
                    //The rule reaction will be disabled and the owner of the guild will be notified.
                    server.RuleEnabled = false;

                    ServerListsManager.SaveServerList();

                    IDMChannel dm = await guild.Owner.GetOrCreateDMChannelAsync();

                    await dm.SendMessageAsync(
                        $"Your rule reaction on the Discord server **{guild.Name}** has been disabled due to the message being deleted.\n" +
                        "You can enable it again after setting a new reaction message with the command `setuprulesmessage` and then enabling the feature again with `togglerulereaction`.");
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                Logger.Log(ex.ToString(), LogVerbosity.Error);
#else
                Logger.Log(ex.Message, LogVerbosity.Error);
#endif
            }
        }
Exemple #6
0
        public async Task MessageBulkDeleted(IReadOnlyCollection <Cacheable <IMessage, ulong> > cacheable,
                                             ISocketMessageChannel channel)
        {
            try
            {
                SocketGuild guild  = ((SocketGuildChannel)channel).Guild;
                ServerList  server = ServerListsManager.GetServer(guild);

                //Depending on how many message were deleted, this could take awhile. Or well I assume that, it would need to be tested
                foreach (Cacheable <IMessage, ulong> cache in cacheable)
                {
                    if (cache.Id != server.RuleMessageId)
                    {
                        continue;
                    }

                    //The rule reaction will be disabled and the owner of the guild will be notified.
                    server.RuleEnabled = false;

                    ServerListsManager.SaveServerList();

                    IDMChannel dm = await guild.Owner.GetOrCreateDMChannelAsync();

                    await dm.SendMessageAsync(
                        $"Your rule reaction on the Discord server **{guild.Name}** has been disabled due to the message being deleted.\n" +
                        "You can enable it again after setting setting a new reaction message with the command `setuprulesmessage` and then enabling the feature again with `togglerulereaction`.");

                    return;
                }
            }
            catch (Exception ex)
            {
                Logger.Error("An error occured while managing a message bulk deleted event! {@Exception}", ex);
            }
        }
Exemple #7
0
        public async Task SetRuleRole([Remainder] string roleName = "")
        {
            if (string.IsNullOrWhiteSpace(roleName))             //Make sure the user actually provided a role
            {
                await Context.Channel.SendMessageAsync("You need to provide a role name!");

                return;
            }

            SocketRole role = RoleUtils.GetGuildRole(Context.Guild, roleName);

            if (role == null)             //Make sure the role exists
            {
                await Context.Channel.SendMessageAsync($"The role **{roleName}** doesn't exist!");

                return;
            }

            //Modify the server settings to update for the new role
            ServerListsManager.GetServer(Context.Guild).RuleRoleId = role.Id;
            ServerListsManager.SaveServerList();

            await Context.Channel.SendMessageAsync(
                $"The role that users shell receive after successfully reacting to the rules will be the **{role.Name}** role.");
        }
Exemple #8
0
        public async Task LeftServer(SocketGuild guild)
        {
            try
            {
                //Remove the server settings from the serverlist.json file
                ServerList server = ServerListsManager.GetServer(guild);
                ServerListsManager.RemoveServer(server);

                ServerListsManager.SaveServerList();

                //Log that the bot left a guild, if enabled
                if (Config.bot.ReportGuildEventsToOwner)
                {
                    await Global.BotOwner.SendMessageAsync($"LOG: Left guild {guild.Name}({guild.Id})");
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                Logger.Log(ex.ToString(), LogVerbosity.Error);
#else
                Logger.Log(ex.Message, LogVerbosity.Error);
#endif
            }
        }
Exemple #9
0
        /// <summary>
        /// Checks that a given user is the owner of a guild, and returns the result
        /// </summary>
        /// <param name="context"></param>
        /// <param name="command"></param>
        /// <param name="services"></param>
        /// <returns></returns>
        public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command,
                                                                        IServiceProvider services)
        {
            //Check if the user is the actual owner of the Guild
            if (context.User.Id == context.Guild.OwnerId)
            {
                return(Task.FromResult(PreconditionResult.FromSuccess()));
            }

            ulong userId = ServerListsManager.GetServer((SocketGuild)context.Guild).GetAGuildOwner(context.User.Id);

            if (allowOtherOwners && userId != 0)
            {
                return(Task.FromResult(PreconditionResult.FromSuccess()));
            }
            if (!allowOtherOwners && userId != 0)
            {
                return(Task.FromResult(PreconditionResult.FromError(
                                           "Sorry, but only the primary owner of this Discord server can run this command!")));
            }

            return(Task.FromResult(
                       PreconditionResult.FromError(
                           "You are not a owner of this Discord server, you cannot run this command!")));
        }
Exemple #10
0
        public async Task AddRoleToRoleMention(string roleToChangeName, string roleToNotAllowToMention)
        {
            SocketRole roleNotToMention = RoleUtils.GetGuildRole(Context.Guild, roleToChangeName);
            SocketRole role             = RoleUtils.GetGuildRole(Context.Guild, roleToNotAllowToMention);

            if (roleNotToMention == null || role == null)
            {
                await Context.Channel.SendMessageAsync(
                    $"Either the **{roleToChangeName}** role doesn't exist or the **{roleToNotAllowToMention}** role doesn't exist!");

                return;
            }

            if (!role.IsMentionable)
            {
                await Context.Channel.SendMessageAsync($"The **{role}** role is already not mentionable by anyone!");

                return;
            }

            ServerListsManager.GetServer(Context.Guild).CreateRoleToRoleMention(roleNotToMention.Id, role.Id);
            ServerListsManager.SaveServerList();

            await Context.Channel.SendMessageAsync(
                $"The **{roleNotToMention.Name}** role will not be allowed to mention the **{role.Name}** role.");
        }
Exemple #11
0
        public async Task SetWarnsKick(int warningsNeeded)
        {
            if (warningsNeeded < 1)
            {
                await Context.Channel.SendMessageAsync(
                    "You need to set warnings for auto kick to be 1 or more warnings!");

                return;
            }

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

            server.WarningsKickAmount = warningsNeeded;

            //If the server's warnings for ban is lower then warnings for kick amount, then set it to one more then kick amount
            if (server.WarningsBanAmount < warningsNeeded)
            {
                server.WarningsBanAmount = warningsNeeded + 1;
            }

            ServerListsManager.SaveServerList();

            await Context.Channel.SendMessageAsync(
                $"{warningsNeeded} warnings will now be required for a user to be automatically kicked.");
        }
Exemple #12
0
        public async Task SetupSpam()
        {
            IDMChannel dm = await Context.User.GetOrCreateDMChannelAsync();

            ServerList   server = ServerListsManager.GetServer(Context.Guild);
            EmbedBuilder embed  = new EmbedBuilder();

            await Context.Channel.SendMessageAsync("Setup anti-spam status was sent to your dms.");

            //Initial embed setup
            embed.WithTitle("Anti-Spam Setup Status");
            embed.WithColor(new Color(255, 81, 168));
            embed.WithDescription(
                $"<:Menu:537572055760109568> Here is your anti-spam setup status for **{Context.Guild.Name}**.\nSee [here]({Global.websiteServerSetup + "anti-spam/"}) for more help.\n\n");
            embed.WithThumbnailUrl(Context.Guild.IconUrl);
            embed.WithCurrentTimestamp();

            //Mention user spam
            string mentionUserTitle = "<:Cross:537572008574189578> Mention user spam is disabled!";
            string mentionUserDes   =
                $"If a message with more then {server.AntiSpamSettings.MentionUsersPercentage}% of the server's users are mentioned, they will be warned.";

            if (server.AntiSpamSettings.MentionUserEnabled)
            {
                mentionUserTitle = "<:Check:537572054266806292> Mention user spam is enabled!";
            }

            //Role to role mentions
            embed.AddField(mentionUserTitle, mentionUserDes);
            embed.AddField("Role to Role mention",
                           $"**{server.AntiSpamSettings.RoleToRoleMentionWarnings}** mentions of the same user will result in one warning");

            await dm.SendMessageAsync("", false, embed.Build());
        }
Exemple #13
0
        public async Task GetOptRoles()
        {
            //Get all opt roles
            OptRole[] optRoles = ServerListsManager.GetServer(Context.Guild).RoleGives.ToArray();

            //Setup string builder
            StringBuilder message = new StringBuilder();

            message.Append("**Opt Roles**\n");

            if (optRoles.Length == 0)
            {
                //There are no opt roles
                message.Append("There are no opt roles!");
            }
            else
            {
                foreach (OptRole optRole in optRoles)
                {
                    //There are opt roles, so add them to the String Builder
                    IRole role = RoleUtils.GetGuildRole(Context.Guild, optRole.RoleToGiveId);

                    message.Append(optRole.RoleRequiredId == 0
                                                ? $"`{optRole.Name}` -> **{role.Name}**\n"
                                                : $"`{optRole.Name}` -> **{role.Name}** (Requires **{RoleUtils.GetGuildRole(Context.Guild, optRole.RoleRequiredId).Name}**)\n");
                }
            }

            await Context.Channel.SendMessageAsync(message.ToString());
        }
        public async Task ToggleGoodbyeMessage()
        {
            ServerList server = ServerListsManager.GetServer(Context.Guild);

            if (server.WelcomeChannelId == 0)
            {
                await Context.Channel.SendMessageAsync(
                    "You need to set a channel first for were the message will be put. Use the command `setup welcomechannel [?channel]` to set a channel.");

                return;
            }

            bool isGoodbyeMessageEnabled = server.GoodbyeMessageEnabled = !server.GoodbyeMessageEnabled;

            ServerListsManager.SaveServerList();

            if (isGoodbyeMessageEnabled)
            {
                await Context.Channel.SendMessageAsync("The custom goodbye message is enabled.");
            }
            else
            {
                await Context.Channel.SendMessageAsync("The custom goodbye message is disabled.");
            }
        }
        public async Task SetupWelcomeChannel([Remainder] SocketTextChannel channel = null)
        {
            ServerList server = ServerListsManager.GetServer(Context.Guild);

            if (channel == null)
            {
                //The welcome/goodbye channel hasn't been set
                if (server.WelcomeChannelId == 0)
                {
                    await Context.Channel.SendMessageAsync(
                        "There is no welcome/goodbye message channel set! Run the command `setup welcomechannel [channel]` with a text channel name as the argument to set one up.");

                    return;
                }

                //Disable the welcome and goodbye message and set their channel to 0
                server.WelcomeChannelId      = 0;
                server.WelcomeMessageEnabled = false;
                server.GoodbyeMessageEnabled = false;
                ServerListsManager.SaveServerList();

                await Context.Channel.SendMessageAsync(
                    "The custom welcome/goodbye message was disabled since no channel was provided when this command was ran.");

                return;
            }

            //Set the new channel
            server.WelcomeChannelId = channel.Id;
            ServerListsManager.SaveServerList();

            await Context.Channel.SendMessageAsync(
                $"The custom welcome/goodbye messages will be put into the {channel.Mention} channel.");
        }
        public async Task SetRuleEmoji([Remainder] Emoji emoji)
        {
            ServerListsManager.GetServer(Context.Guild).RuleReactionEmoji = emoji.Name;
            ServerListsManager.SaveServerList();

            await Context.Channel.SendMessageAsync($"The emoji was set to '{emoji.Name}'.");
        }
Exemple #17
0
        public async Task UserLeft(SocketGuildUser user)
        {
            try
            {
                if (!user.IsBot)
                {
                    ServerList server = ServerListsManager.GetServer(user.Guild);
                    if (server.GoodbyeMessageEnabled)
                    {
                        //Format the message
                        string addUserMention = server.WelcomeGoodbyeMessage.Replace("[user]", user.Username);

                        //Get the welcome channel and send the message
                        SocketTextChannel channel =
                            client.GetGuild(server.GuildId).GetTextChannel(server.WelcomeChannelId);

                        if (channel != null)
                        {
                            await channel.SendMessageAsync(addUserMention);
                        }
                        else
                        {
                            server.WelcomeMessageEnabled = false;
                            server.WelcomeChannelId      = 0;

                            ServerListsManager.SaveServerList();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("An error occured while managing on user left event! {@Exception}", ex);
            }
        }
        public async Task SetMentionUserThreshold(int threshold)
        {
            ServerListsManager.GetServer(Context.Guild).AntiSpamSettings.MentionUsersPercentage = threshold;
            ServerListsManager.SaveServerList();

            await Context.Channel.SendMessageAsync(
                $"The threshold for amount of users in a message was set to {threshold}.");
        }
Exemple #19
0
        public async Task RoleDeleted(SocketRole role)
        {
            try
            {
                SocketGuild guild  = role.Guild;
                ServerList  server = ServerListsManager.GetServer(guild);

                //Setup the dm channel even though we might not even use it just makes it so I don't have to repeat this a whole bunch of times.
                IDMChannel dm = await guild.Owner.GetOrCreateDMChannelAsync();

                //The rule role was deleted
                if (role.Id == server.RuleRoleId)
                {
                    server.RuleEnabled = false;
                    ServerListsManager.SaveServerList();

                    await dm.SendMessageAsync(
                        $"Your rule reaction on the Discord server **{guild.Name}** has been disabled due to the role being deleted.\n" +
                        "You can enable it again after setting a new role with the command `setuprulerole` and then enabling the feature again with `togglerulereaction`.");

                    return;
                }

                //Check all server role points roles
                List <ServerRolePoints> rolePointsToRemove =
                    server.ServerRolePoints.Where(rolePoint => role.Id == rolePoint.RoleId).ToList();
                foreach (ServerRolePoints toRemove in rolePointsToRemove)
                {
                    await dm.SendMessageAsync(
                        $"The **{role.Name}** was deleted which was apart of the {toRemove.PointsRequired} server points role. This server points role was deleted. ({guild.Name})");

                    server.ServerRolePoints.Remove(toRemove);
                    ServerListsManager.SaveServerList();
                    return;
                }

                //Check to see if all the role to role pings still exist
                List <ServerRoleToRoleMention> rolesToRemove = server.RoleToRoleMentions
                                                               .Where(roles => roles.RoleId == role.Id || roles.RoleNotToMentionId == role.Id).ToList();
                foreach (ServerRoleToRoleMention roleToRemove in rolesToRemove)
                {
                    await dm.SendMessageAsync(
                        $"The **{role.Name}** role was deleted which was apart of the **{roleToRemove.RoleNotToMentionId}** => **{roleToRemove.RoleId}**. This role to role ping was deleted. ({guild.Name})");

                    server.RoleToRoleMentions.Remove(roleToRemove);
                    ServerListsManager.SaveServerList();
                    return;
                }

                //Check all permission roles
                BotCheckServerSettings.CheckServerPerms(server);
            }
            catch (Exception ex)
            {
                Logger.Error("An error occured while managing role deleted event! {@Exception}", ex);
            }
        }
Exemple #20
0
        public async Task ToggleRuleReaction()
        {
            ServerList server = ServerListsManager.GetServer(Context.Guild);

            //If the rule reaction feature is already enabled, disable it
            if (server.RuleEnabled)
            {
                server.RuleEnabled = false;
                ServerListsManager.SaveServerList();

                await Context.Channel.SendMessageAsync("The rule reaction feature is now disabled.");

                return;
            }

            //Make sure the rule message channel still exists
            SocketTextChannel ruleChannel = Context.Guild.GetTextChannel(server.RuleMessageChannelId);

            if (ruleChannel == null)
            {
                server.RuleMessageChannelId = 0;                 //Reset it back to 0 so we don't have to write it
                ServerListsManager.SaveServerList();

                return;
            }

            //Make sure the message still exists
            IMessage rulesMessage = await ruleChannel.GetMessageAsync(server.RuleMessageId);

            if (rulesMessage == null)
            {
                await Context.Channel.SendMessageAsync($"The rules message that is meant to belong in the {ruleChannel.Mention} channel doesn't exist anymore!");

                return;
            }

            //Check the emoji
            if (!server.RuleReactionEmoji.ContainsUnicodeCharacter())
            {
                await Context.Channel.SendMessageAsync("The emoji that is meant to be used is invalid!");

                return;
            }

            //Ok, everything is all good to go, now just to enable it

            //First add our reaction
            IUserMessage rulesMessageUser = (IUserMessage)rulesMessage;
            await rulesMessageUser.AddReactionAsync(new Emoji(server.RuleReactionEmoji));

            //And actually enable the feature
            server.RuleEnabled = true;
            ServerListsManager.SaveServerList();

            await Context.Channel.SendMessageAsync("The rule reaction feature is now enabled!");
        }
        public async Task AddOptRole(string optRoleBaseName, string roleToAssignName,
                                     [Remainder] string requiredRoleName = "")
        {
            SocketRole roleToAssign = RoleUtils.GetGuildRole(Context.Guild, roleToAssignName);

            //Check to make sure the role exists first
            if (roleToAssign == null)
            {
                await Context.Channel.SendMessageAsync("You need to input a valid role to give!");

                return;
            }

            //If a required role was specified, check to make sure it exists
            SocketRole requiredRole = null;

            if (!string.IsNullOrWhiteSpace(requiredRoleName))
            {
                requiredRole = RoleUtils.GetGuildRole(Context.Guild, requiredRoleName);
                if (requiredRole == null)
                {
                    await Context.Channel.SendMessageAsync($"Role {requiredRoleName} doesn't exist!");

                    return;
                }
            }

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

            //Check to make sure a role give doesn't already exist first
            if (server.GetOptRole(optRoleBaseName) != null)
            {
                await Context.Channel.SendMessageAsync(
                    $"An opt role with the name '{optRoleBaseName}' already exists!");

                return;
            }

            //Create and add our new opt role
            OptRole roleGive = new OptRole
            {
                Name           = optRoleBaseName,
                RoleToGiveId   = roleToAssign.Id,
                RoleRequiredId = 0
            };

            if (requiredRole != null)
            {
                roleGive.RoleRequiredId = requiredRole.Id;
            }

            server.RoleGives.Add(roleGive);
            ServerListsManager.SaveServerList();

            await Context.Channel.SendMessageAsync($"An opt role with the name `{optRoleBaseName}` was created.");
        }
        public async Task ToggleMentionUserSpam()
        {
            ServerList server = ServerListsManager.GetServer(Context.Guild);

            server.AntiSpamSettings.MentionUserEnabled = !server.AntiSpamSettings.MentionUserEnabled;

            ServerListsManager.SaveServerList();
            await Context.Channel.SendMessageAsync(
                $"Mention user anti-spam was set to {server.AntiSpamSettings.MentionUserEnabled}.");
        }
        public static async Task <RestVoiceChannel> CreateAutoVCChannel(SocketGuild guild, string baseName)
        {
            RestVoiceChannel vcChannel =
                await guild.CreateVoiceChannelAsync($"➕ New {baseName} VC");

            ServerAudioVoiceChannel audioVoiceChannel = new ServerAudioVoiceChannel(vcChannel.Id, baseName);

            ServerListsManager.GetServer(guild).AutoVoiceChannels.Add(audioVoiceChannel);
            ServerListsManager.SaveServerList();

            return(vcChannel);
        }
Exemple #24
0
        /// <summary>
        /// Checks all server settings, auto vc channels, active vc channels and the welcome message
        /// </summary>
        /// <returns></returns>
        public async Task CheckConnectedServerSettings()
        {
            Logger.Log("Checking pre-connected server settings...");

            //To avoid saving possibly 100 times we will only save once if something has changed
            bool somethingChanged = false;

            List <ServerList> serversToRemove = new List <ServerList>();

            ServerList[] servers = ServerListsManager.GetServers();
            foreach (ServerList server in servers)
            {
                //The bot is not longer in this guild, remove it from the server settings
                if (_client.GetGuild(server.GuildId) == null)
                {
                    somethingChanged = true;
                    serversToRemove.Add(server);
                    continue;
                }

                await CheckServerWelcomeSettings(server);
                await CheckServerRuleMessageChannel(server);

                CheckServerVoiceChannels(server);
                CheckServerActiveVoiceChannels(server);
                CheckServerPerms(server);

                //Start up all votes
                foreach (Vote serverVote in server.Votes)
                {
#pragma warning disable 4014
                    Task.Run(() => VotingService.RunVote(serverVote, _client.GetGuild(server.GuildId)));
#pragma warning restore 4014
                }
            }

            //Like all the other ones, we remove all the unnecessary servers after to avoid System.InvalidOperationException
            foreach (ServerList toRemove in serversToRemove)
            {
                Logger.Log($"The bot is not longer in the {toRemove.GuildId}, Removing server settings...");
                ServerListsManager.RemoveServer(toRemove);
            }

            //If a server was updated then save the ServerList.json file
            if (somethingChanged)
            {
                ServerListsManager.SaveServerList();
            }

            Logger.Log("Checked all server settings.");
        }
        public async Task Permissions()
        {
            StringBuilder sb     = new StringBuilder();
            ServerList    server = ServerListsManager.GetServer(Context.Guild);

            sb.Append("**__Permissions__**\n");

            foreach (ServerList.CommandPermission perm in server.CommandPermissions)
            {
                sb.Append($"__`{perm.Command}`__\nRoles: {FormatRoles(perm.Roles, Context.Guild)}\n\n");
            }

            await Context.Channel.SendMessageAsync(sb.ToString());
        }
Exemple #26
0
        /// <summary>
        /// Ends a vote running on a guild
        /// <para>If the vote is running, it will END it!</para>
        /// </summary>
        /// <param name="vote">The vote to end</param>
        /// <param name="guild"></param>
        /// <returns></returns>
        public static async Task EndVote(Vote vote, SocketGuild guild)
        {
            Logger.Log("The vote ended.", LogVerbosity.Debug);

            vote.CancellationToken.Cancel();

            SocketUser user = guild.GetUser(vote.VoteStarterUserId);

            //Remove from user's last vote
            UserAccountsManager.GetAccount((SocketGuildUser)user).UserLastVoteId = 0;
            UserAccountsManager.SaveAccounts();

            //Create a new embed with the results
            EmbedBuilder embed = new EmbedBuilder();

            embed.WithTitle(vote.VoteTitle);
            embed.WithDescription(vote.VoteDescription +
                                  $"\nThe vote is now over! Here are the results:\n**Yes**: {vote.YesCount}\n**No**: {vote.NoCount}");
            if (user != null)
            {
                embed.WithFooter($"Vote started by {user} and ended at {DateTime.Now:g}.", user.GetAvatarUrl());
            }
            else
            {
                embed.WithFooter("Vote started by: a person who left the guild :(");
            }

            //Modify the message
            IMessage message =
                await guild.GetTextChannel(vote.VoteMessageChannelId).GetMessageAsync(vote.VoteMessageId);

            await MessageUtils.ModifyMessage(message as IUserMessage, embed);

            //Send the user who started the vote a message about their vote is over
            if (user != null)
            {
                EmbedBuilder userDmEmbed = new EmbedBuilder();
                userDmEmbed.WithTitle("Vote: " + vote.VoteTitle);
                userDmEmbed.WithDescription($"Your vote that you started on the **{guild.Name}** guild is now over.\n" +
                                            $"You can see the results [here](https://discordapp.com/channels/{guild.Id}/{vote.VoteMessageChannelId}/{vote.VoteMessageId}).");

                IDMChannel userDm = await user.GetOrCreateDMChannelAsync();

                await userDm.SendMessageAsync("", false, userDmEmbed.Build());
            }

            //Remove our vote from the server's vote list
            ServerListsManager.GetServer(guild).Votes.Remove(vote);
            ServerListsManager.SaveServerList();
        }
        public async Task SetServerPoints(uint amount)
        {
            if (amount < 10)
            {
                await Context.Channel.SendMessageAsync("The points amount cannot be less then 10!");

                return;
            }

            ServerListsManager.GetServer(Context.Guild).PointGiveAmount = amount;
            ServerListsManager.SaveServerList();

            await Context.Channel.SendMessageAsync($"The amount of points given out will now be {amount}.");
        }
        public async Task GetBannedChannels()
        {
            ServerList    server = ServerListsManager.GetServer(Context.Guild);
            StringBuilder final  = new StringBuilder();

            final.Append("**All banned channels**: \n");

            foreach (ulong channel in server.BannedChannels)
            {
                final.Append($"<#{channel}> (**Id**: {channel})\n");
            }

            await Context.Channel.SendMessageAsync(final.ToString());
        }
        public async Task SetServerPointsCooldown(int time)
        {
            if (time < 5)
            {
                await Context.Channel.SendMessageAsync("The time cannot be less then 5 seconds!");

                return;
            }

            ServerListsManager.GetServer(Context.Guild).PointsGiveCooldownTime = time;
            ServerListsManager.SaveServerList();

            await Context.Channel.SendMessageAsync($"The cooldown time is now {time} seconds.");
        }
Exemple #30
0
        /// <summary>
        /// Checks all the bot's auto voice channels
        /// </summary>
        /// <param name="server"></param>
        public static void CheckServerVoiceChannels(ServerList server)
        {
            //Get all the voice channels that have been deleted
            List <ServerVoiceChannel> autoVcChannelsToDelete = (from autoVoiceChannel in server.AutoVoiceChannels
                                                                let vcChannel = _client.GetGuild(server.GuildId).GetVoiceChannel(autoVoiceChannel.Id)
                                                                                where vcChannel == null
                                                                                select autoVoiceChannel).ToList();

            foreach (ServerVoiceChannel voiceChannel in autoVcChannelsToDelete)
            {
                server.AutoVoiceChannels.Remove(voiceChannel);
            }

            ServerListsManager.SaveServerList();
        }