예제 #1
0
        /// <summary>Called when a change is made to a server. </summary>
        internal async Task GuildUpdateAsync(SocketGuild oldGuild, SocketGuild newGuild)
        {
            foreach (PluginInfo plugin in GlobalConfig.PluginInfo)
            {
                if (plugin.MessageReceivedAsync != null)
                {
                    if (GlobalConfig.RunPluginFunctionsAsynchronously)
                        #pragma warning disable 4014
                    {
                        plugin.GuildUpdate(oldGuild, newGuild);
                    }
                        #pragma warning restore 4014
                    else
                    {
                        await plugin.GuildUpdate(oldGuild, newGuild);
                    }
                }
            }

            RavenGuild guild = RavenDb.GetGuild(oldGuild.Id);

            // Compare changes
            if (oldGuild.Name != newGuild.Name)
            {
                guild.Name = newGuild.Name;
            }

            guild.TotalUsers = (uint)newGuild.Users.Count;
            guild.Save();
        }
예제 #2
0
        private static Task <RestUserMessage> BlacklistDisplayRoles(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (guild.GuildSettings.BlacklistedRoles.Count == 0)
            {
                return(channel.SendMessageAsync("There are currently no blacklisted roles."));
            }

            string roles = "Blacklisted Roles:\n";

            foreach (ulong i in guild.GuildSettings.BlacklistedRoles)
            {
                var tempRole = channel.Guild.Roles.FirstOrDefault(x => x.Id == i);

                if (tempRole is null)
                {
                    roles += $"DELETED-ROLE ({i})\n";
                }
                else
                {
                    roles += $"{tempRole.Name} ({i})\n";
                }
            }

            if (roles.Length > 1900)
            {
                return(channel.SendMessageAsync("Too many roles to list. Cutting off after 1800 characters.\n"
                                                + roles.Substring(0, 1800)));
            }
            else
            {
                return(channel.SendMessageAsync("```cs\n" + roles + "\n```"));
            }
        }
예제 #3
0
        private static Task <RestUserMessage> LsSetMinXpTime(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (args.ElementAtOrDefault(1) is null)
            {
                return(channel.SendMessageAsync(GetMissingParam("MinXpTime", typeof(int))));
            }
            if (!int.TryParse(args.ElementAt(1), out int val))
            {
                return(channel.SendMessageAsync(ParamWrongFormat("MinXpTime", typeof(int))));
            }

            // TODO: Unhardcode clamped global xp values
            if (val < 30)
            {
                return(channel.SendMessageAsync("MinXpTime must be greater than or equal to 30."));
            }
            if (val > 180)
            {
                return(channel.SendMessageAsync("MinXpTime must not be greater than 180."));
            }

            guild.GuildSettings.LevelConfig.SecondsBetweenXpGiven = (uint)val;
            guild.UserConfiguration[userId] = MessageBox.LevelSettings;
            guild.Save();
            return(SelectSubMenu(guild, userId, channel, MessageBox.LevelSettings));
        }
예제 #4
0
        private static Task <RestUserMessage> BlacklistDisplayUsers(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (guild.GuildSettings.BlacklistedUsers.Count == 0)
            {
                return(channel.SendMessageAsync("There are currently no blacklisted users."));
            }

            string users = "Blacklisted Users:\n";

            foreach (ulong i in guild.GuildSettings.BlacklistedUsers)
            {
                var user = channel.Guild.Users.FirstOrDefault(x => x.Id == i);
                if (user is null)
                {
                    RavenUser deletedRavenUser = guild.Users.FirstOrDefault(x => x.UserId == i);
                    string    oldUsername      = deletedRavenUser == null ? "Unknown" : deletedRavenUser.Username + "#" + deletedRavenUser.Discriminator;
                    users += $"USER-LEFT (ID: {i} - Old Name: {oldUsername})\n";
                }
                else
                {
                    users += $"{user.Username} ({i})\n";
                }
            }

            if (users.Length > 1900)
            {
                return(channel.SendMessageAsync("Too many users to list. Cutting off after 1800 characters.\n"
                                                + users.Substring(0, 1800)));
            }
            else
            {
                return(channel.SendMessageAsync("```cs\n" + users + "\n```"));
            }
        }
예제 #5
0
        private static Task <RestUserMessage> LoggingSetChannel(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (args.ElementAtOrDefault(1) is null) // If they didn't provide a channel name
            {
                return(channel.SendMessageAsync(GetMissingParam("ChannelName", typeof(string))));
            }

            Console.WriteLine(string.Join('-', args, 1));
            var tempChannel = channel.Guild.Channels.FirstOrDefault(x => x.Name == string.Join('-', args.Skip(1)).ToLower());

            tempChannel = tempChannel ?? channel.Guild.Channels.FirstOrDefault(x => x.Name.Contains(string.Join('-', args.Skip(1)).ToLower()));

            if (tempChannel is null) // If we found no matching channels
            {
                return(channel.SendMessageAsync("The specified channel could not be found. Please try again."));
            }
            if (!(tempChannel is SocketTextChannel)) // If the channel found was not a valid text channel
            {
                return(channel.SendMessageAsync("The specified channel was not a text channel"));
            }

            guild.LoggingSettings.ChannelId = tempChannel.Id;
            guild.UserConfiguration[userId] = MessageBox.LoggingSettings;
            guild.Save();
            return(SelectSubMenu(guild, userId, channel, MessageBox.LoggingSettings));
        }
예제 #6
0
        private static Task <RestUserMessage> LsRemoveLevelBinding(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (args.ElementAtOrDefault(1) is null)
            {
                return(channel.SendMessageAsync(GetMissingParam("Level", typeof(byte))));
            }
            if (!byte.TryParse(args.ElementAt(1), out byte val))
            {
                return(channel.SendMessageAsync(ParamWrongFormat("Level", typeof(byte))));
            }
            if (val <= 1)
            {
                return(channel.SendMessageAsync("There are no bindings for level 1 or below."));
            }

            if (!guild.GuildSettings.LevelConfig.RankBindings.ContainsKey(val))
            {
                return(channel.SendMessageAsync("There is no rank bound to the specified level."));
            }

            guild.GuildSettings.LevelConfig.RankBindings.Remove(val);
            guild.UserConfiguration[userId] = MessageBox.LevelSettings;
            guild.Save();
            return(SelectSubMenu(guild, userId, channel, MessageBox.LevelSettings));
        }
예제 #7
0
        private static Task <RestUserMessage> LsListLevelBindings(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (guild.GuildSettings.LevelConfig.RankBindings.Count == 0)
            {
                return(channel.SendMessageAsync("There are no bindings currently set."));
            }

            List <string> ranks = new List <string>()
            {
                ""
            };
            int i = 0;

            foreach (var rank in guild.GuildSettings.LevelConfig.RankBindings)
            {
                string value = $"{rank.Key}: {rank.Value}\n";
                ranks[i] += value;
                if (ranks[i].Length <= 1900)
                {
                    continue;
                }
                ranks.Add("");
                i++;
            }

            var ii = 1;

            while (ii < ranks.Count)
            {
                channel.SendMessageAsync(ranks[ii - 1]);
                ii++;
            }

            return(channel.SendMessageAsync(ranks[ii - 1]));
        }
예제 #8
0
        public async Task Kick([Remainder] SocketGuildUser user)
        {
            if (user.Hierarchy > Context.Guild.CurrentUser.Hierarchy)
            {
                await ReplyAsync("I cannot kick someone who has a higher role that me. Caw.");

                return;
            }

            RavenGuild guild = RavenDb.GetGuild(Context.Guild.Id);
            bool       sent  = false;

            if (guild.GuildSettings.CustomKickMessage != null)
            {
                if (guild.GuildSettings.CustomKickMessage.Enabled)
                {
                    await ReplyAsync(guild.GuildSettings.CustomKickMessage.Message);

                    sent = true;
                }
            }

            if (!sent)
            {
                await ReplyAsync($"Bye, {user.Nickname ?? user.Username}. You probably wont be missed.");
            }
            await user.KickAsync();
        }
예제 #9
0
        private static Task <RestUserMessage> BlacklistDisplayChannels(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (guild.GuildSettings.BlacklistedChannels.Count == 0)
            {
                return(channel.SendMessageAsync("There are currently no blacklisted channels."));
            }

            string channels = "Blacklisted Channels:\n";

            foreach (ulong i in guild.GuildSettings.BlacklistedChannels)
            {
                var tempChannel = channel.Guild.Channels.FirstOrDefault(x => x.Name == string.Join('-', args.Skip(1)).ToLower());
                tempChannel = tempChannel ?? channel.Guild.Channels.FirstOrDefault(x => x.Name.Contains(string.Join('-', args.Skip(1)).ToLower()));

                if (tempChannel is null)
                {
                    channels += $"#INVALID-CHANNEL ({i})\n";
                }
                else
                {
                    channels += $"#{tempChannel.Name} ({i})\n";
                }
            }

            if (channels.Length > 1900)
            {
                return(channel.SendMessageAsync("Too many channels to list. Cutting off after 1800 characters.\n"
                                                + channels.Substring(0, 1800)));
            }
            else
            {
                return(channel.SendMessageAsync("```cs\n" + channels + "\n```"));
            }
        }
예제 #10
0
        private static Task <RestUserMessage> LsSetMaxXp(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (args.ElementAtOrDefault(1) is null)
            {
                return(channel.SendMessageAsync(GetMissingParam("MaximumXp", typeof(int))));
            }
            if (!int.TryParse(args.ElementAt(1), out int val))
            {
                return(channel.SendMessageAsync(ParamWrongFormat("MaximumXp", typeof(int))));
            }

            // TODO: Unhardcode clamped global xp values
            if (val <= 1)
            {
                return(channel.SendMessageAsync("MaximumXp must be greater than 1."));
            }
            if (val > 1000)
            {
                return(channel.SendMessageAsync("MaximumXp must not be greater than 1000."));
            }
            if (val < guild.GuildSettings.LevelConfig.MinXpGenerated)
            {
                return(channel.SendMessageAsync("MaximumXp must not be less than the MinimumXp. They can be equal to remove RNG."));
            }

            guild.GuildSettings.LevelConfig.MaxXpGenerated = val;
            guild.UserConfiguration[userId] = MessageBox.LevelSettings;
            guild.Save();
            return(SelectSubMenu(guild, userId, channel, MessageBox.LevelSettings));
        }
예제 #11
0
        //private static Task<RestUserMessage> TEMPLATEFUNCTION(RavenGuild guild, ulong userId, ISocketMessageChannel channel, string[] args) {}

        private static Task <RestUserMessage> LsSetLevelState(RavenGuild guild, ulong userId, SocketTextChannel channel, LevelSettings option)
        {
            guild.GuildSettings.LevelConfig.LevelSettings = option;
            guild.UserConfiguration[userId] = MessageBox.LsSettingSubmenu;
            guild.Save();
            return(SelectSubMenu(guild, userId, channel, MessageBox.LsSettingSubmenu));
        }
예제 #12
0
        /// <summary>Called when a user leaves the server (or is kicked). </summary>
        internal async Task GuildUserLeaveAsync(SocketGuildUser user)
        {
            foreach (PluginInfo plugin in GlobalConfig.PluginInfo)
            {
                if (plugin.MessageReceivedAsync != null)
                {
                    if (GlobalConfig.RunPluginFunctionsAsynchronously)
                        #pragma warning disable 4014
                    {
                        plugin.GuildUserLeave.Invoke(user);
                    }
                        #pragma warning restore 4014
                    else
                    {
                        await plugin.GuildUserLeave(user);
                    }
                }
            }

            // Get the guild this user is in
            RavenGuild guild = RavenDb.GetGuild(user.Guild.Id) ?? RavenDb.CreateNewGuild(user.Guild.Id, user.Guild.Name);

            // Update the total amount of users
            guild.TotalUsers = (uint)user.Guild.Users.Count;

            // Process goodbye message if one is set
            if (guild.GuildSettings.GoodbyeMessage.Enabled)
            {
                // If the targeted channel is null or no longer exists or the message itself is undefined
                if (guild.GuildSettings.GoodbyeMessage.ChannelId is null || user.Guild.GetTextChannel(guild.GuildSettings.GoodbyeMessage.ChannelId.GetValueOrDefault()) is null ||
                    string.IsNullOrWhiteSpace(guild.GuildSettings.GoodbyeMessage.Message))
                {
                    // If the logging channel is setup, exists, and is enabled
                    if (!(guild.LoggingSettings.ChannelId is null) && !(user.Guild.GetTextChannel(guild.LoggingSettings.ChannelId.GetValueOrDefault()) is null) &&
                        guild.LoggingSettings.Enabled)
                    {
                        // Log to the logging channel if it has been set
                        await user.Guild.GetTextChannel(guild.LoggingSettings.ChannelId.Value).SendMessageAsync(null, false, new EmbedBuilder()
                        {
                            Title       = "Warning!",
                            Color       = new Color(255, 128, 0), // Orange
                            Description = "Unable to send goodbye message. Channel or message are currently null. Please reconfigure it.",
                            Footer      = new EmbedFooterBuilder()
                            {
                                Text = $"{DateTime.UtcNow:ddd MMM d yyyy HH mm}"
                            }
                        }.Build());
                    }
                }

                else
                {
                    // Send the Goodbye message and repalce the server or user tags if they are present
                    await user.Guild.GetTextChannel(guild.GuildSettings.GoodbyeMessage.ChannelId.Value)
                    .SendMessageAsync(guild.GuildSettings.GoodbyeMessage.Message
                                      .Replace("%SERVER%", user.Guild.Name)
                                      .Replace("%USER%", user.Username));
                }
            }
예제 #13
0
파일: Config.cs 프로젝트: G01dmaster/Raven
        public async Task ConfigAsync()
        {
            RavenGuild guild = RavenDb.GetGuild(Context.Guild.Id);

            guild.UserConfiguration[Context.User.Id] = MessageBox.BaseMenu;
            guild.Save();
            await ReplyAsync(ConfigHandler.GetCodeBlock(File.ReadAllText($"{Directory.GetCurrentDirectory()}/ConfigTextFiles/{MenuFiles.BaseMenu.ToString()}.txt")));
        }
예제 #14
0
        private static Task <RestUserMessage> GeneralSetPrefix(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (args.ElementAtOrDefault(1) is null) // If they didn't provide a channel name
            {
                return(channel.SendMessageAsync(GetMissingParam("Prefix", typeof(string))));
            }

            guild.GuildSettings.Prefix      = string.Join(' ', args.Skip(1));
            guild.UserConfiguration[userId] = MessageBox.GeneralSettings;
            guild.Save();
            return(SelectSubMenu(guild, userId, channel, MessageBox.GeneralSettings));
        }
예제 #15
0
        // Override the CheckPermissions method
        public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
        {
            // Check if this user is a Guild User, which is the only context where roles exist
            if (context.User is SocketGuildUser gUser)
            {
                RavenGuild guild = RavenDb.GetGuild(context.Guild.Id);
                return(Task.FromResult(guild.GuildSettings.BlacklistedModules.Any(x => string.Equals(x, command.Module.Name, StringComparison.CurrentCultureIgnoreCase))
                    ? PreconditionResult.FromError("This command is part of a module that has been banned/disallowed in this server.")
                    : PreconditionResult.FromSuccess()));
            }

            return(Task.FromResult(PreconditionResult.FromSuccess()));
        }
예제 #16
0
        private static Task <RestUserMessage> BlacklistAddCommand(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (args.ElementAtOrDefault(1) is null)
            {
                return(channel.SendMessageAsync(GetMissingParam("CommandName", typeof(string))));
            }

            string name = string.Join(' ', args.Skip(1)).ToLower();

            guild.GuildSettings.BlacklistedCommands.Add(name);
            guild.Save();
            return(SelectSubMenu(guild, userId, channel, MessageBox.ConfigureDisallowedCommands));
        }
예제 #17
0
        private static Task <RestUserMessage> GoodbyePreviewMessage(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (string.IsNullOrWhiteSpace(guild.GuildSettings.GoodbyeMessage.Message))
            {
                return(channel.SendMessageAsync("There is currently no message set."));
            }

            Task.Run(async() =>
            {
                await channel.SendMessageAsync(guild.GuildSettings.GoodbyeMessage.Message
                                               .Replace("%SERVER%", channel.Guild.Name)
                                               .Replace("%USER%", "Raven"));
            });
            guild.UserConfiguration[userId] = MessageBox.GoodbyeSettings;
            guild.Save();
            return(SelectSubMenu(guild, userId, channel, MessageBox.GoodbyeSettings));
        }
예제 #18
0
        public async Task GetProfileAsync([Remainder] string target)
        {
            RavenGuild guild = RavenDb.GetGuild(Context.Guild.Id);
            Regex      regex = new Regex(@"<@([0-9]*)>");
            Match      match = regex.Match(target);

            if (match.Success)
            {
                // See if what they gave was a real person
                ulong.TryParse(match.Groups[1].Value, out ulong id);
                if (id is 0)
                {
                    await ReplyAsync("Invalid User Mentioned.");

                    return;
                }

                RavenUser mentionedUser = guild.GetUser(id);
                if (mentionedUser is null)
                {
                    await ReplyAsync("The user specified doesn't exist within the system.");

                    return;
                }

                // Gotem.
                await ReplyAsync(null, false, DiscordEvents.GetUserProfile(id, guild));
            }

            else
            {
                RavenUser user = guild.Users.FirstOrDefault(x => x.Username.StartsWith(target));
                if (user is null)
                {
                    await ReplyAsync("Couldn't find anyone who's name was at all like that. To be fair, it's not a very indepth search.");

                    return;
                }

                await ReplyAsync(null, false, DiscordEvents.GetUserProfile(user.UserId, guild));
            }
        }
예제 #19
0
        private static Task <RestUserMessage> GoodbyeSetMessage(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (string.IsNullOrWhiteSpace(args.ElementAtOrDefault(1)))
            {
                return(channel.SendMessageAsync(GetMissingParam("Message", typeof(string))));
            }

            string input = string.Join(' ', args.Skip(1));

            if (input.Length > 1900)
            {
                return(channel.SendMessageAsync("You cannot put in a message over 1900 characters. " +
                                                "The bot limits this as a saftey net so you don't go to close to Discord's native 2000 character limit."));
            }

            guild.GuildSettings.GoodbyeMessage.Message = input;
            guild.UserConfiguration[userId]            = MessageBox.GoodbyeSettings;
            guild.Save();
            return(SelectSubMenu(guild, userId, channel, MessageBox.GoodbyeSettings));
        }
예제 #20
0
        private static Task <RestUserMessage> BlacklistAddRole(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (args.ElementAtOrDefault(1) is null) // If they didn't provide a role name
            {
                return(channel.SendMessageAsync(GetMissingParam("RoleName", typeof(string))));
            }

            var tempRole = channel.Guild.Roles.FirstOrDefault(x => x.Name == string.Join(' ', args.Skip(1)));

            tempRole = tempRole ?? channel.Guild.Roles.FirstOrDefault(x => x.Name.Contains(string.Join(' ', args.Skip(1))));

            if (tempRole is null) // If we found no matching channels
            {
                return(channel.SendMessageAsync("The specified role could not be found. Please try again."));
            }

            guild.GuildSettings.BlacklistedRoles.Add(tempRole.Id);
            guild.Save();
            return(SelectSubMenu(guild, userId, channel, MessageBox.ConfigureBlacklistedRoles));
        }
예제 #21
0
        private static Task <RestUserMessage> BlacklistRemoveModule(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (args.ElementAtOrDefault(1) is null)
            {
                return(channel.SendMessageAsync(GetMissingParam("ModuleName", typeof(string))));
            }

            string name = string.Join(' ', args.Skip(1)).ToLower();

            if (guild.GuildSettings.BlacklistedModules.Any(x => x == name))
            {
                guild.GuildSettings.BlacklistedModules.Remove(name);
                guild.Save();
                return(SelectSubMenu(guild, userId, channel, MessageBox.ConfigureDisallowedModules));
            }

            else
            {
                return(channel.SendMessageAsync("The specified module was not blacklisted."));
            }
        }
예제 #22
0
        private static Task <RestUserMessage> RemoveTag(RavenGuild guild, ulong userId, SocketTextChannel channel,
                                                        string[] args)
        {
            string name = args.ElementAtOrDefault(1);

            if (name is null)
            {
                return(channel.SendMessageAsync(GetMissingParam("TagName", typeof(string))));
            }

            int tagIndex = guild.Tags.FindIndex(x => string.Equals(x.Tag, name, StringComparison.CurrentCultureIgnoreCase));

            if (tagIndex is - 1)
            {
                return(channel.SendMessageAsync("Specified tag name does not exist."));
            }

            guild.Tags.RemoveAt(tagIndex);
            guild.Save();
            return(SelectSubMenu(guild, userId, channel, MessageBox.TagSettings));
        }
예제 #23
0
        private static Task <RestUserMessage> AddTag(RavenGuild guild, ulong userId, SocketTextChannel channel,
                                                     string[] args)
        {
            string name     = args.ElementAtOrDefault(1);
            string category = args.ElementAtOrDefault(2);

            if (name is null)
            {
                return(channel.SendMessageAsync(GetMissingParam("TagName", typeof(string))));
            }

            if (guild.Tags.Any(x => string.Equals(x.Tag, name, StringComparison.CurrentCultureIgnoreCase)))
            {
                return(channel.SendMessageAsync("Specified tag name already exists."));
            }

            if (category is null)
            {
                return(channel.SendMessageAsync(GetMissingParam("TagCategory", typeof(string))));
            }

            if (args.ElementAtOrDefault(3) is null)
            {
                return(channel.SendMessageAsync(GetMissingParam("TagMessage", typeof(string))));
            }

            string   message = string.Join(" ", args.Skip(3));
            RavenTag tag     = new RavenTag
            {
                AuthorId = userId,
                Category = category,
                Tag      = name,
                Message  = message
            };

            guild.Tags.Add(tag);
            guild.Save();
            return(SelectSubMenu(guild, userId, channel, MessageBox.TagSettings));
        }
예제 #24
0
        private static Task <RestUserMessage> BlacklistAddUser(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (args.ElementAtOrDefault(1) is null)
            {
                return(channel.SendMessageAsync(GetMissingParam("Username", typeof(string))));
            }

            string name = string.Join(' ', args.Skip(1)).ToLower();

            var user = (channel.Guild.Users.FirstOrDefault(x => (x.Username + "#" + x.DiscriminatorValue).Contains(name)) ??
                        channel.Guild.Users.FirstOrDefault(x => x.Nickname.Contains(name))) ??
                       channel.Guild.Users.FirstOrDefault(x => x.Id.ToString() == name);

            if (user is null)
            {
                return(channel.SendMessageAsync("Could not find a matching user."));
            }

            guild.GuildSettings.BlacklistedUsers.Add(user.Id);
            guild.Save();
            return(SelectSubMenu(guild, userId, channel, MessageBox.ConfigureBlacklistedUsers));
        }
예제 #25
0
        private static Task <RestUserMessage> BlacklistRemoveUser(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (args.ElementAtOrDefault(1) is null)
            {
                return(channel.SendMessageAsync(GetMissingParam("UserId", typeof(ulong))));
            }

            if (!ulong.TryParse(args.ElementAtOrDefault(1), out ulong id))
            {
                return(channel.SendMessageAsync(ParamWrongFormat("UserId", typeof(ulong))));
            }

            if (guild.GuildSettings.BlacklistedUsers.Any(x => x == id))
            {
                guild.GuildSettings.BlacklistedUsers.Remove(id);
                guild.Save();
                return(SelectSubMenu(guild, userId, channel, MessageBox.ConfigureBlacklistedUsers));
            }

            else
            {
                return(channel.SendMessageAsync("The specified user was not blacklisted."));
            }
        }
예제 #26
0
        private static Task <RestUserMessage> BlacklistDisplayCommands(RavenGuild guild, SocketTextChannel channel)
        {
            if (guild.GuildSettings.BlacklistedModules.Count == 0)
            {
                return(channel.SendMessageAsync("There are currently no blacklisted commands."));
            }

            string commands = "Blacklisted Commands:\n";

            foreach (string i in guild.GuildSettings.BlacklistedCommands)
            {
                commands += i + "\n";
            }

            if (commands.Length > 1900)
            {
                return(channel.SendMessageAsync("Too many commands to list. Cutting off after 1800 characters.\n"
                                                + commands.Substring(0, 1800)));
            }
            else
            {
                return(channel.SendMessageAsync("```cs\n" + commands + "\n```"));
            }
        }
예제 #27
0
        private static Task <RestUserMessage> BlacklistRemoveChannel(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (args.ElementAtOrDefault(1) is null) // If they didn't provide a channel name
            {
                return(channel.SendMessageAsync(GetMissingParam("ChannelId", typeof(uint))));
            }

            if (!uint.TryParse(args.ElementAtOrDefault(1), out uint id))
            {
                return(channel.SendMessageAsync(ParamWrongFormat("ChannelId", typeof(uint))));
            }

            if (guild.GuildSettings.BlacklistedChannels.Any(x => x == id))
            {
                guild.GuildSettings.BlacklistedChannels.Remove(id);
                guild.Save();
                return(SelectSubMenu(guild, userId, channel, MessageBox.GeneralConfigureBlacklistedChannels));
            }

            else
            {
                return(channel.SendMessageAsync("The specified channel was not blacklisted."));
            }
        }
예제 #28
0
        private static Task <RestUserMessage> LsAddLevelBinding(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (args.ElementAtOrDefault(1) is null)
            {
                return(channel.SendMessageAsync(GetMissingParam("Level", typeof(byte))));
            }
            if (!byte.TryParse(args.ElementAt(1), out byte val))
            {
                return(channel.SendMessageAsync(ParamWrongFormat("Level", typeof(byte))));
            }
            if (val <= 1)
            {
                return(channel.SendMessageAsync("You cannot bind a rank to level 1 or below."));
            }
            if (guild.GuildSettings.LevelConfig.RankBindings.ContainsKey(val))
            {
                return(channel.SendMessageAsync($"Level {val} already has a binding assigned to it."));
            }

            if (string.IsNullOrWhiteSpace(args.ElementAtOrDefault(2)))
            {
                return(channel.SendMessageAsync(GetMissingParam("RankName", typeof(string))));
            }

            string value = string.Join(' ', args.Skip(2));

            if (value.Length > 32)
            {
                return(channel.SendMessageAsync("Rank name cannot be over 32 characters."));
            }

            guild.GuildSettings.LevelConfig.RankBindings[val] = value;
            guild.UserConfiguration[userId] = MessageBox.LevelSettings;
            guild.Save();
            return(SelectSubMenu(guild, userId, channel, MessageBox.LevelSettings));
        }
예제 #29
0
        /// <summary>Called when a user joins the server. </summary>
        internal async Task GuildUserJoinAsync(SocketGuildUser user)
        {
            foreach (PluginInfo plugin in GlobalConfig.PluginInfo)
            {
                if (plugin.MessageReceivedAsync != null)
                {
                    if (GlobalConfig.RunPluginFunctionsAsynchronously)
                        #pragma warning disable 4014
                    {
                        plugin.GuildUserLeave.Invoke(user);
                    }
                        #pragma warning restore 4014
                    else
                    {
                        await plugin.GuildUserLeave(user);
                    }
                }
            }

            // Add it to the global database if they don't exist
            if (RavenDb.GetUser(user.Id) is null)
            {
                RavenDb.CreateNewUser(user.Id, user.Username, user.DiscriminatorValue, user.GetAvatarUrl() ?? user.GetDefaultAvatarUrl());
            }

            // Get the guild this user is in
            RavenGuild guild = RavenDb.GetGuild(user.Guild.Id) ?? RavenDb.CreateNewGuild(user.Guild.Id, user.Guild.Name);

            // Update the total amount of users
            guild.TotalUsers = (uint)user.Guild.Users.Count;

            // If they rejoined, we'll store their old name to log
            bool   rejoined = false;
            string username = string.Empty;

            // Get the user from that guild
            RavenUser guildUser = guild.GetUser(user.Id);
            if (guildUser is null) // if they don't exist, we'll need to create them
            {
                guild.CreateNewUser(user.Id, user.Username, user.DiscriminatorValue, user.GetAvatarUrl() ?? user.GetDefaultAvatarUrl());
            }

            else
            {
                // They rejoined, update their name in case/discrim in case it changed
                rejoined                = true;
                username                = guildUser.Username + "#" + guildUser.Discriminator;
                guildUser.Username      = user.Username;
                guildUser.Discriminator = user.DiscriminatorValue;
                guild.Save(); // Save the updated information, while storing the old one for logging purposes
            }

            // Process welcome message if one is set
            if (guild.GuildSettings.WelcomeMessage.Enabled)
            {
                // If the targeted channel is null or no longer exists or the message itself is undefined
                if (guild.GuildSettings.WelcomeMessage.ChannelId is null || user.Guild.GetTextChannel(guild.GuildSettings.WelcomeMessage.ChannelId.GetValueOrDefault()) is null ||
                    string.IsNullOrWhiteSpace(guild.GuildSettings.WelcomeMessage.Message))
                {
                    // If the logging channel is setup, exists, and is enabled
                    if (!(guild.LoggingSettings.ChannelId is null) && !(user.Guild.GetTextChannel(guild.LoggingSettings.ChannelId.GetValueOrDefault()) is null) &&
                        guild.LoggingSettings.Enabled)
                    {
                        // Log to the logging channel if it has been set
                        await user.Guild.GetTextChannel(guild.LoggingSettings.ChannelId.Value).SendMessageAsync(null, false, new EmbedBuilder()
                        {
                            Title       = "Warning!",
                            Color       = new Color(255, 128, 0), // Orange
                            Description = "Unable to send welcome message. Channel or message are currently null. Please reconfigure it.",
                            Footer      = new EmbedFooterBuilder()
                            {
                                Text = $"{DateTime.UtcNow:ddd MMM d yyyy HH mm}"
                            }
                        }.Build());
                    }
                }

                else
                {
                    // Send the welcome message and repalce the server or user tags if they are present
                    await user.Guild.GetTextChannel(guild.GuildSettings.WelcomeMessage.ChannelId.Value)
                    .SendMessageAsync(guild.GuildSettings.WelcomeMessage.Message
                                      .Replace("%SERVER%", user.Guild.Name)
                                      .Replace("%USER%", user.Username));
                }
            }
예제 #30
0
        /// <summary>Process the actual options</summary>
        public static Task <RestUserMessage> SelectOption(RavenGuild guild, ulong userId, SocketTextChannel channel, string[] args)
        {
            if (!uint.TryParse(args[0], out uint temp))
            {
                return(InvalidOption(channel));
            }

            MessageBox option = (MessageBox)temp;

            switch (guild.UserConfiguration[userId])
            {
            // Don't know how this would be possible, but better safe than sorry.
            case MessageBox.BaseMenu:
                return(SelectSubMenu(guild, userId, channel, option));

            // Level Settings Sub Menu
            case MessageBox.LevelSettings:
            {
                if ((int)option is 7)         // We need to cast our submenus to a higher value otherwise they cause problems when selecting options
                {
                    option = MessageBox.LsSettingSubmenu;
                }
                switch (option)
                {
                case MessageBox.LsSetMinXp:
                    return(LsSetMinXp(guild, userId, channel, args));

                case MessageBox.LsSetMaxXp:
                    return(LsSetMaxXp(guild, userId, channel, args));

                case MessageBox.LsSetXpTime:
                    return(LsSetMinXpTime(guild, userId, channel, args));

                case MessageBox.LsAddLevelBinding:
                    return(LsAddLevelBinding(guild, userId, channel, args));

                case MessageBox.LsRemoveLevelBinding:
                    return(LsRemoveLevelBinding(guild, userId, channel, args));

                case MessageBox.LsListLevelBindings:
                    return(LsListLevelBindings(guild, userId, channel, args));

                case MessageBox.LsSettingSubmenu:
                    return(SelectSubMenu(guild, userId, channel, option));

                default:
                    return(InvalidOption(channel));
                }
            }

            // Level Settings Sub-Sub Menu
            case MessageBox.LsSettingSubmenu:
            {
                switch (option)
                {
                case MessageBox.LsSettingDisabled:
                    return(LsSetLevelState(guild, userId, channel, LevelSettings.Disabled));

                case MessageBox.LsSettingGlobalLevel:
                    return(LsSetLevelState(guild, userId, channel, LevelSettings.GlobalLeveling));

                case MessageBox.LsSettingGuildLevel:
                    return(LsSetLevelState(guild, userId, channel, LevelSettings.GuildLeveling));

                default:
                    return(InvalidOption(channel));
                }
            }

            // Welcome Message Settings Sub Menu
            case MessageBox.WelcomeSettings:
            {
                switch (option)
                {
                case MessageBox.WelcomeToggle:
                    guild.GuildSettings.WelcomeMessage.Enabled = !guild.GuildSettings.WelcomeMessage.Enabled;
                    guild.UserConfiguration[userId]            = MessageBox.WelcomeSettings;
                    guild.Save();
                    return(SelectSubMenu(guild, userId, channel, MessageBox.WelcomeSettings));

                case MessageBox.WelcomeChannel:
                    return(WelcomeSetChannel(guild, userId, channel, args));

                case MessageBox.WelcomeMessage:
                    return(WelcomeSetMessage(guild, userId, channel, args));

                case MessageBox.WelcomePreview:
                    return(WelcomePreviewMessage(guild, userId, channel, args));

                default:
                    return(InvalidOption(channel));
                }
            }

            // Goodbye Settings Submenu
            case MessageBox.GoodbyeSettings:
            {
                switch (option)
                {
                case MessageBox.GoodbyeToggle:
                    guild.GuildSettings.GoodbyeMessage.Enabled = !guild.GuildSettings.GoodbyeMessage.Enabled;
                    guild.UserConfiguration[userId]            = MessageBox.GoodbyeSettings;
                    guild.Save();
                    return(SelectSubMenu(guild, userId, channel, MessageBox.GoodbyeSettings));

                case MessageBox.GoodbyeChannel:
                    return(GoodbyeSetChannel(guild, userId, channel, args));

                case MessageBox.GoodbyeMessage:
                    return(GoodbyeSetMessage(guild, userId, channel, args));

                case MessageBox.GoodbyePreview:
                    return(GoodbyePreviewMessage(guild, userId, channel, args));

                default:
                    return(InvalidOption(channel));
                }
            }

            // Welcome Message Settings Sub Menu
            case MessageBox.LoggingSettings:
            {
                switch (option)
                {
                case MessageBox.LoggingModuleEnabled:
                    guild.LoggingSettings.Enabled   = !guild.LoggingSettings.Enabled;
                    guild.UserConfiguration[userId] = MessageBox.LoggingSettings;
                    guild.Save();
                    return(SelectSubMenu(guild, userId, channel, MessageBox.LoggingSettings));

                case MessageBox.LoggingChannel:
                    return(LoggingSetChannel(guild, userId, channel, args));

                case MessageBox.LoggingEnableAll:
                    guild.LoggingSettings.Enabled      = true;
                    guild.LoggingSettings.Join         = true;
                    guild.LoggingSettings.Leave        = true;
                    guild.LoggingSettings.Ban          = true;
                    guild.LoggingSettings.Msg          = true;
                    guild.LoggingSettings.User         = true;
                    guild.LoggingSettings.VoiceChannel = true;
                    guild.LoggingSettings.Role         = true;
                    guild.LoggingSettings.GuildUpdate  = true;
                    guild.UserConfiguration[userId]    = MessageBox.LoggingSettings;
                    guild.Save();
                    return(SelectSubMenu(guild, userId, channel, MessageBox.LoggingSettings));

                case MessageBox.LoggingDisableAll:
                    guild.LoggingSettings.Enabled      = false;
                    guild.LoggingSettings.Join         = false;
                    guild.LoggingSettings.Leave        = false;
                    guild.LoggingSettings.Ban          = false;
                    guild.LoggingSettings.Msg          = false;
                    guild.LoggingSettings.User         = false;
                    guild.LoggingSettings.VoiceChannel = false;
                    guild.LoggingSettings.Role         = false;
                    guild.LoggingSettings.GuildUpdate  = false;
                    guild.UserConfiguration[userId]    = MessageBox.LoggingSettings;
                    guild.Save();
                    return(SelectSubMenu(guild, userId, channel, MessageBox.LoggingSettings));

                case MessageBox.LoggingJoin:
                    guild.LoggingSettings.Join      = !guild.LoggingSettings.Join;
                    guild.UserConfiguration[userId] = MessageBox.LoggingSettings;
                    guild.Save();
                    return(SelectSubMenu(guild, userId, channel, MessageBox.LoggingSettings));

                case MessageBox.LoggingLeave:
                    guild.LoggingSettings.Leave     = !guild.LoggingSettings.Leave;
                    guild.UserConfiguration[userId] = MessageBox.LoggingSettings;
                    guild.Save();
                    return(SelectSubMenu(guild, userId, channel, MessageBox.LoggingSettings));

                case MessageBox.LoggingBan:
                    guild.LoggingSettings.Ban       = !guild.LoggingSettings.Ban;
                    guild.UserConfiguration[userId] = MessageBox.LoggingSettings;
                    guild.Save();
                    return(SelectSubMenu(guild, userId, channel, MessageBox.LoggingSettings));

                case MessageBox.LoggingMsg:
                    guild.LoggingSettings.Msg       = !guild.LoggingSettings.Msg;
                    guild.UserConfiguration[userId] = MessageBox.LoggingSettings;
                    guild.Save();
                    return(SelectSubMenu(guild, userId, channel, MessageBox.LoggingSettings));

                case MessageBox.LoggingUser:
                    guild.LoggingSettings.User      = !guild.LoggingSettings.User;
                    guild.UserConfiguration[userId] = MessageBox.LoggingSettings;
                    guild.Save();
                    return(SelectSubMenu(guild, userId, channel, MessageBox.LoggingSettings));

                case MessageBox.LoggingRole:
                    guild.LoggingSettings.Role      = !guild.LoggingSettings.Role;
                    guild.UserConfiguration[userId] = MessageBox.LoggingSettings;
                    guild.Save();
                    return(SelectSubMenu(guild, userId, channel, MessageBox.LoggingSettings));

                case MessageBox.LoggingVc:
                    guild.LoggingSettings.VoiceChannel = !guild.LoggingSettings.VoiceChannel;
                    guild.UserConfiguration[userId]    = MessageBox.LoggingSettings;
                    guild.Save();
                    return(SelectSubMenu(guild, userId, channel, MessageBox.LoggingSettings));

                case MessageBox.LoggingGuildUpdate:
                    guild.LoggingSettings.GuildUpdate = !guild.LoggingSettings.GuildUpdate;
                    guild.UserConfiguration[userId]   = MessageBox.LoggingSettings;
                    guild.Save();
                    return(SelectSubMenu(guild, userId, channel, MessageBox.LoggingSettings));

                default:
                    return(InvalidOption(channel));
                }
            }

            // Generic Settings (prefix, blacklists, module control, and probably more in the future)
            case MessageBox.GeneralSettings:
            {
                switch (option)
                {
                case MessageBox.GeneralSetPrefix:
                    return(GeneralSetPrefix(guild, userId, channel, args));

                case MessageBox.GeneralToggleInviteBlocking:
                    guild.GuildSettings.AutoblockInviteLinks = !guild.GuildSettings.AutoblockInviteLinks;
                    guild.UserConfiguration[userId]          = MessageBox.GeneralSettings;
                    guild.Save();
                    return(SelectSubMenu(guild, userId, channel, MessageBox.GeneralSettings));

                default:
                    return(InvalidOption(channel));
                }
            }

            // Tag Settings Sub Menu
            case MessageBox.TagSettings:
            {
                switch (option)
                {
                case MessageBox.TagAdd:
                    return(AddTag(guild, userId, channel, args));

                case MessageBox.TagRemove:
                    return(RemoveTag(guild, userId, channel, args));

                default:
                    return(InvalidOption(channel));
                }
            }

            case MessageBox.BlacklistSettings:
            {
                switch ((int)option)
                {
                case 1:
                    option = MessageBox.ConfigureDisallowedModules;
                    break;

                case 2:
                    option = MessageBox.ConfigureDisallowedCommands;
                    break;

                case 3:
                    option = MessageBox.ConfigureBlacklistedChannels;
                    break;

                case 4:
                    option = MessageBox.ConfigureBlacklistedRoles;
                    break;

                case 5:
                    option = MessageBox.ConfigureBlacklistedUsers;
                    break;
                }

                switch (option)
                {
                case MessageBox.ConfigureDisallowedModules:
                case MessageBox.ConfigureDisallowedCommands:
                case MessageBox.ConfigureBlacklistedChannels:
                case MessageBox.ConfigureBlacklistedRoles:
                case MessageBox.ConfigureBlacklistedUsers:
                    return(SelectSubMenu(guild, userId, channel, option));

                default:
                    return(InvalidOption(channel));
                }
            }

            case MessageBox.ConfigureDisallowedModules:
            {
                switch (option)
                {
                case MessageBox.BlacklistAddTo:
                    return(BlacklistAddModule(guild, userId, channel, args));

                case MessageBox.BlacklistRemoveFrom:
                    return(BlacklistRemoveModule(guild, userId, channel, args));

                case MessageBox.BlacklistDisplay:
                    return(BlacklistDisplayModules(guild, channel));

                default:
                    return(InvalidOption(channel));
                }
            }

            case MessageBox.ConfigureDisallowedCommands:
            {
                switch (option)
                {
                case MessageBox.BlacklistAddTo:
                    return(BlacklistAddCommand(guild, userId, channel, args));

                case MessageBox.BlacklistRemoveFrom:
                    return(BlacklistRemoveCommand(guild, userId, channel, args));

                case MessageBox.BlacklistDisplay:
                    return(BlacklistDisplayCommands(guild, channel));

                default:
                    return(InvalidOption(channel));
                }
            }

            case MessageBox.ConfigureBlacklistedChannels:
            {
                switch (option)
                {
                case MessageBox.BlacklistAddTo:
                    return(BlacklistAddChannel(guild, userId, channel, args));

                case MessageBox.BlacklistRemoveFrom:
                    return(BlacklistRemoveChannel(guild, userId, channel, args));

                case MessageBox.BlacklistDisplay:
                    return(BlacklistDisplayChannels(guild, userId, channel, args));

                default:
                    return(InvalidOption(channel));
                }
            }

            case MessageBox.ConfigureBlacklistedRoles:
            {
                switch (option)
                {
                case MessageBox.BlacklistAddTo:
                    return(BlacklistAddRole(guild, userId, channel, args));

                case MessageBox.BlacklistRemoveFrom:
                    return(BlacklistRemoveRole(guild, userId, channel, args));

                case MessageBox.BlacklistDisplay:
                    return(BlacklistDisplayRoles(guild, userId, channel, args));

                default:
                    return(InvalidOption(channel));
                }
            }

            case MessageBox.ConfigureBlacklistedUsers:
            {
                switch (option)
                {
                case MessageBox.BlacklistAddTo:
                    return(BlacklistAddUser(guild, userId, channel, args));

                case MessageBox.BlacklistRemoveFrom:
                    return(BlacklistRemoveUser(guild, userId, channel, args));

                case MessageBox.BlacklistDisplay:
                    return(BlacklistDisplayUsers(guild, userId, channel, args));

                default:
                    return(InvalidOption(channel));
                }
            }

            default:
                guild.UserConfiguration.Remove(userId);
                guild.Save();
                return(channel.SendMessageAsync("I don't know how you got here, but I am gonna exit the menu just to be safe.\n" +
                                                "(You should probably report this if it's reproducible.)"));
            }
        }