public SocketGuildDialogContextBase(GuildCommandContext Context)
     : base(Context)
 {
     this.Config  = Context.cfg;
     this.Guild   = Context.Guild;
     this.Channel = Context.GuildChannel;
     this.User    = Context.GuildUser;
 }
Exemple #2
0
        protected override ArgumentParseResult TryParseArgumentsGuildSynchronous(GuildCommandContext context)
        {
            if (context.Arguments.Count == 0)
            {
                Mode = CommandMode.list;
                Role = null;
            }
            else
            {
                if (!Enum.TryParse(context.Arguments.First, out Mode))
                {
                    return(new ArgumentParseResult(ARGS[0], $"Unable to parse `{context.Arguments.First}` to a valid command mode!"));
                }

                context.Arguments.Index++;

                if (context.Arguments.Count == 0 && Mode != CommandMode.list)
                {
                    return(new ArgumentParseResult(ARGS[1], $"Mode `{Mode}` requires a role as second argument!"));
                }

                if (Mode != CommandMode.list)
                {
                    if (!ArgumentParsing.TryParseRole(context, context.Arguments.First, out Role))
                    {
                        if (Mode == CommandMode.add)
                        {
                            return(new ArgumentParseResult(ARGS[1], $"Could not parse `{context.Arguments.First}` to a valid role!"));
                        }
                        else
                        {
                            if (!ulong.TryParse(context.Arguments.First, out RoleId))
                            {
                                return(new ArgumentParseResult(ARGS[1], $"Could not parse `{context.Arguments.First}` to a valid role!"));
                            }
                        }
                    }

                    if (Role != null)
                    {
                        RoleId = Role.Id;
                    }

                    bool hasRole = EventLogger.AutoAssignRoleIds.Contains(RoleId);
                    if (Mode == CommandMode.add && hasRole)
                    {
                        return(new ArgumentParseResult(ARGS[1], $"{Role.Mention} is already amongst the auto assign roles!"));
                    }
                    else if (Mode == CommandMode.remove && !hasRole)
                    {
                        return(new ArgumentParseResult(ARGS[1], $"Can not remove {Role.Mention} from the list of auto assign roles, as it isn't in that list already!"));
                    }
                }
            }

            return(ArgumentParseResult.SuccessfullParse);
        }
Exemple #3
0
        protected override async Task HandleCommandGuildAsync(GuildCommandContext context)
        {
            switch (Mode)
            {
            case CommandMode.list:
                EmbedBuilder embed = new EmbedBuilder()
                {
                    Title       = "Roles automatically assigned to newly joined users",
                    Color       = BotCore.EmbedColor,
                    Description = EventLogger.AutoAssignRoleIds.Count == 0 ?
                                  "No Roles"
                        :
                                  EventLogger.AutoAssignRoleIds.OperationJoin(", ", (ulong roleId) =>
                    {
                        SocketRole role = context.Guild.GetRole(roleId);
                        if (role != null)
                        {
                            return(role.Mention);
                        }
                        else
                        {
                            return(Markdown.InlineCodeBlock(roleId));
                        }
                    })
                };
                await context.Channel.SendEmbedAsync(embed);

                break;

            case CommandMode.add:
                EventLogger.AutoAssignRoleIds.Add(RoleId);
                await SettingsModel.SaveSettings();

                await context.Channel.SendEmbedAsync($"Added {Role.Mention} to the list of roles automatically assigned to new users!");

                break;

            case CommandMode.remove:
                EventLogger.AutoAssignRoleIds.Remove(RoleId);
                await SettingsModel.SaveSettings();

                await context.Channel.SendEmbedAsync($"Removed {(Role == null ? Markdown.InlineCodeBlock(RoleId) : Role.Mention)} from the list of roles automatically assigned to new users!");

                break;
            }
        }
Exemple #4
0
        protected override async Task HandleCommandGuildAsync(GuildCommandContext context)
        {
            bool foundExisting = GuildChannelHelper.TryGetChannelConfig(Channel.Id, out GuildChannelConfiguration channelConfig);

            if (!foundExisting)
            {
                channelConfig = new GuildChannelConfiguration(Channel.Id);
            }

            foreach (var config in Configs)
            {
                switch (config.Item1)
                {
                case ConfigIdentifier.allowshitposting:
                    channelConfig.AllowShitposting = config.Item2;
                    break;

                case ConfigIdentifier.allowcommands:
                    channelConfig.AllowCommands = config.Item2;
                    break;
                }
            }

            GuildChannelHelper.SetChannelConfig(channelConfig);

            await SettingsModel.SaveSettings();

            EmbedBuilder embed = new EmbedBuilder()
            {
                Color       = BotCore.EmbedColor,
                Description = channelConfig.ToString()
            };

            if (Configs.Count > 0)
            {
                embed.Title = $"Configuration applied for channel {Channel.Name}";
            }
            else
            {
                embed.Title = $"Configuration of channel {Channel.Name}";
            }

            await context.Channel.SendEmbedAsync(embed);
        }
Exemple #5
0
        protected override ArgumentParseResult TryParseArgumentsGuildSynchronous(GuildCommandContext context)
        {
            channel = null;

            if (!Enum.TryParse(context.Arguments[0], out channelType))
            {
                return(new ArgumentParseResult(ARGS[0], $"Could not parse to an output channel type. Available are: `{Macros.GetEnumNames<OutputChannelType>()}`"));
            }

            if (context.Arguments.Count == 2)
            {
                if (!ArgumentParsing.TryParseGuildChannel(context, context.Arguments[1], out channel))
                {
                    return(new ArgumentParseResult(ARGS[1], $"Could not parse to a channel in this guild"));
                }
            }

            return(ArgumentParseResult.SuccessfullParse);
        }
Exemple #6
0
        protected override ArgumentParseResult TryParseArgumentsGuildSynchronous(GuildCommandContext context)
        {
            if (!Enum.TryParse(context.Arguments[0], out RoleIdentifier))
            {
                return(new ArgumentParseResult(ARGS[0], $"Could not parse to a role identifier. Available are: `{string.Join(", ", Enum.GetNames(typeof(SettingRoles)))}`"));
            }

            if (context.Arguments.Count == 2)
            {
                if (!ArgumentParsing.TryParseRole(context, context.Arguments[1], out Role))
                {
                    return(new ArgumentParseResult(ARGS[1], $"Could not parse to a role in this guild"));
                }
            }
            else
            {
                Role = null;
            }

            return(ArgumentParseResult.SuccessfullParse);
        }
Exemple #7
0
        protected override ArgumentParseResult TryParseArgumentsGuildSynchronous(GuildCommandContext context)
        {
            if (!ArgumentParsing.TryParseGuildChannel(context, context.Arguments[0], out Channel))
            {
                return(new ArgumentParseResult(ARGS[0], "Failed to parse to a guild channel!"));
            }

            Configs.Clear();

            if (context.Arguments.Count > 1)
            {
                context.Arguments.Index++;
                foreach (string arg in context.Arguments)
                {
                    string[] argSplit = arg.Split(':');
                    if (argSplit.Length == 2)
                    {
                        if (!Enum.TryParse(argSplit[0], out ConfigIdentifier configIdentifier))
                        {
                            return(new ArgumentParseResult(ARGS[1], $"{arg} - Could not parse to config identifier. Available are `{Macros.GetEnumNames<ConfigIdentifier>()}`!"));
                        }
                        if (!bool.TryParse(argSplit[1], out bool setting))
                        {
                            return(new ArgumentParseResult(ARGS[1], $"{arg} - Could not parse boolean value!"));
                        }
                        Configs.Add(new Tuple <ConfigIdentifier, bool>(configIdentifier, setting));
                    }
                    else
                    {
                        return(new ArgumentParseResult(ARGS[1], $"{arg} - Could not split into config identifer and setting!"));
                    }
                }
                context.Arguments.Index--;
            }

            return(ArgumentParseResult.SuccessfullParse);
        }
Exemple #8
0
 public static async Task SendAdminCommandUsedMessage(IDMCommandContext context, Command command)
 {
     if (GuildChannelHelper.TryGetChannel(GuildChannelHelper.AdminCommandUsageLogChannelId, out SocketTextChannel channel))
     {
         EmbedBuilder debugembed = new EmbedBuilder
         {
             Color = BotCore.EmbedColor,
             Title = $"Admin-Only command used by {context.User.Username}#{context.User.Discriminator}",
         };
         debugembed.AddField("Command and Arguments", $"Matched Command```{command.Syntax}```Arguments```{context.Message.Content}".MaxLength(1021) + "```");
         string location;
         if (GuildCommandContext.TryConvert(context, out IGuildCommandContext guildContext))
         {
             SocketTextChannel locationChannel = channel.Guild.GetTextChannel(guildContext.Channel.Id);
             location = $"Guild `{guildContext.Guild.Name}` Channel {(locationChannel == null ? Markdown.InlineCodeBlock(guildContext.Channel.Name) : locationChannel.Mention)}";
         }
         else
         {
             location = "Private Message to Bot";
         }
         debugembed.AddField("Location", location);
         await channel.SendEmbedAsync(debugembed);
     }
 }
Exemple #9
0
        protected override async Task HandleCommandAsync(CommandContext context)
        {
            GuildChannelHelper.TryGetChannel(GuildChannelHelper.DebugChannelId, out SocketTextChannel debugChannel);
            GuildChannelHelper.TryGetChannel(GuildChannelHelper.WelcomingChannelId, out SocketTextChannel welcomingChannel);
            GuildChannelHelper.TryGetChannel(GuildChannelHelper.AdminCommandUsageLogChannelId, out SocketTextChannel adminCommandUsageLogging);
            GuildChannelHelper.TryGetChannel(GuildChannelHelper.AdminNotificationChannelId, out SocketTextChannel adminNotificationChannel);
            GuildChannelHelper.TryGetChannel(GuildChannelHelper.InteractiveMessagesChannelId, out SocketTextChannel interactiveMessagesChannel);
            SocketRole adminRole        = null;
            SocketRole botNotifications = null;
            SocketRole minecraftBranch  = null;
            SocketRole mute             = null;

            if (GuildCommandContext.TryConvert(context, out GuildCommandContext guildContext))
            {
                adminRole        = guildContext.Guild.GetRole(SettingsModel.AdminRole);
                botNotifications = guildContext.Guild.GetRole(SettingsModel.BotDevRole);
                minecraftBranch  = guildContext.Guild.GetRole(SettingsModel.MinecraftBranchRole);
                mute             = guildContext.Guild.GetRole(SettingsModel.MuteRole);
            }

            EmbedBuilder embed = new EmbedBuilder()
            {
                Title       = "Current Settings",
                Color       = BotCore.EmbedColor,
                Description = $"YNB Bot {Var.VERSION}"
            };
            StringBuilder debugLogging = new StringBuilder("Logging Channel: ");

            if (debugChannel == null)
            {
                debugLogging.AppendLine(Markdown.InlineCodeBlock(GuildChannelHelper.DebugChannelId));
            }
            else
            {
                debugLogging.AppendLine(debugChannel.Mention);
            }
            for (int i = 0; i < SettingsModel.debugLogging.Length; i++)
            {
                bool option = SettingsModel.debugLogging[i];
                debugLogging.AppendLine($"{(DebugCategories)i}: { (option ? "**enabled**" : "disabled") }");
            }
            embed.AddField("Debug Logging", debugLogging);
            embed.AddField("Channels", $"Welcoming: { (welcomingChannel == null ? Markdown.InlineCodeBlock(GuildChannelHelper.WelcomingChannelId) : welcomingChannel.Mention) }\n" +
                           $"Interactive Messages: {(interactiveMessagesChannel == null ? Markdown.InlineCodeBlock(GuildChannelHelper.InteractiveMessagesChannelId) : interactiveMessagesChannel.Mention)}\n" +
                           $"Admin Command Usage Logging: {(adminCommandUsageLogging == null ? Markdown.InlineCodeBlock(GuildChannelHelper.AdminCommandUsageLogChannelId) : adminCommandUsageLogging.Mention)}\n" +
                           $"Admin Notifications: {(adminNotificationChannel == null ? Markdown.InlineCodeBlock(GuildChannelHelper.AdminNotificationChannelId) : adminNotificationChannel.Mention)}");

            embed.AddField("Roles", $"Admin Role: { (adminRole == null ? Markdown.InlineCodeBlock(SettingsModel.AdminRole) : adminRole.Mention) }\n" +
                           $"Bot Notifications Role: { (botNotifications == null ? Markdown.InlineCodeBlock(SettingsModel.BotDevRole) : botNotifications.Mention) }\n" +
                           $"Minecraft Branch Role: {(minecraftBranch == null ? Markdown.InlineCodeBlock(SettingsModel.MinecraftBranchRole) : minecraftBranch.Mention)}\n" +
                           $"Mute Role: {(mute == null ? Markdown.InlineCodeBlock(SettingsModel.MuteRole) : mute.Mention)}");

            string bAdmins = SettingsModel.botAdminIDs.OperationJoin(", ", id =>
            {
                SocketGuildUser user = null;
                if (context.IsGuildContext)
                {
                    user = guildContext.Guild.GetUser(id);
                }

                if (user != null)
                {
                    return($"{user.Mention} (`{user.Id}`)");
                }
                else
                {
                    return(Markdown.InlineCodeBlock(user.Id.ToString()));
                }
            });

            embed.AddField($"Bot Admins - {SettingsModel.botAdminIDs.Count}", bAdmins);
            await context.Channel.SendEmbedAsync(embed);
        }
Exemple #10
0
        protected override async Task HandleCommandGuildAsync(GuildCommandContext context)
        {
            if (channel == null)
            {
                ulong channelId = 0;
                switch (channelType)
                {
                case OutputChannelType.debuglogging:
                    channelId = GuildChannelHelper.DebugChannelId;
                    break;

                case OutputChannelType.welcoming:
                    channelId = GuildChannelHelper.WelcomingChannelId;
                    break;

                case OutputChannelType.admincommandlog:
                    channelId = GuildChannelHelper.AdminCommandUsageLogChannelId;
                    break;

                case OutputChannelType.adminnotifications:
                    channelId = GuildChannelHelper.AdminNotificationChannelId;
                    break;

                case OutputChannelType.interactive:
                    channelId = GuildChannelHelper.InteractiveMessagesChannelId;
                    break;

                case OutputChannelType.guildcategory:
                    channelId = GuildChannelHelper.GuildCategoryId;
                    break;
                }

                channel = context.Guild.GetTextChannel(channelId);
                SocketTextChannel textChannel = channel as SocketTextChannel;

                await context.Channel.SendEmbedAsync($"Current setting for `{channelType}` is {(channel == null ? Markdown.InlineCodeBlock(channelId) : (textChannel == null ? channel.Name : textChannel.Mention))}");
            }
            else
            {
                switch (channelType)
                {
                case OutputChannelType.debuglogging:
                    GuildChannelHelper.DebugChannelId = channel.Id;
                    break;

                case OutputChannelType.welcoming:
                    GuildChannelHelper.WelcomingChannelId = channel.Id;
                    break;

                case OutputChannelType.admincommandlog:
                    GuildChannelHelper.AdminCommandUsageLogChannelId = channel.Id;
                    break;

                case OutputChannelType.adminnotifications:
                    GuildChannelHelper.AdminNotificationChannelId = channel.Id;
                    break;

                case OutputChannelType.interactive:
                    GuildChannelHelper.InteractiveMessagesChannelId = channel.Id;
                    break;

                case OutputChannelType.guildcategory:
                    GuildChannelHelper.GuildCategoryId = channel.Id;
                    break;
                }
                await SettingsModel.SaveSettings();

                SocketTextChannel textChannel = channel as SocketTextChannel;

                await context.Channel.SendEmbedAsync($"Set setting for `{channelType}` to {(textChannel == null ? channel.Name : textChannel.Mention)}");
            }
        }
Exemple #11
0
        protected override async Task HandleCommandGuildAsync(GuildCommandContext context)
        {
            if (Role == null)
            {
                ulong roleId = 0;
                switch (RoleIdentifier)
                {
                case SettingRoles.admin:
                    roleId = SettingsModel.AdminRole;
                    break;

                case SettingRoles.botnotifications:
                    roleId = SettingsModel.BotDevRole;
                    break;

                case SettingRoles.minecraftbranch:
                    roleId = SettingsModel.MinecraftBranchRole;
                    break;

                case SettingRoles.mute:
                    roleId = SettingsModel.MuteRole;
                    break;

                case SettingRoles.guildcaptain:
                    roleId = SettingsModel.GuildCaptainRole;
                    break;
                }

                SocketRole role = context.Guild.GetRole(roleId);

                await context.Channel.SendEmbedAsync($"Current setting for `{RoleIdentifier}` is {(role == null ? Markdown.InlineCodeBlock(roleId) : role.Mention)}");
            }
            else
            {
                switch (RoleIdentifier)
                {
                case SettingRoles.admin:
                    SettingsModel.AdminRole = Role.Id;
                    break;

                case SettingRoles.botnotifications:
                    SettingsModel.BotDevRole = Role.Id;
                    break;

                case SettingRoles.minecraftbranch:
                    SettingsModel.MinecraftBranchRole = Role.Id;
                    break;

                case SettingRoles.mute:
                    SettingsModel.MuteRole = Role.Id;
                    break;

                case SettingRoles.guildcaptain:
                    SettingsModel.GuildCaptainRole = Role.Id;
                    break;
                }
                await SettingsModel.SaveSettings();

                await context.Channel.SendEmbedAsync($"Set setting for `{RoleIdentifier}` to {Role.Mention}");
            }
        }
Exemple #12
0
 public SetupDialog(GuildCommandContext Context)
     : base(Context)
 {
 }
 public static bool TestBotPermission(this GuildCommandContext Context, ChannelPermission Permission)
 => Context.Guild.CurrentUser.GetPermissions(Context.GuildChannel).ToList().Contains(Permission);
Exemple #14
0
        private async Task processMessage(SocketUserMessage message)
        {
            try
            {
                //Start actual processing logic.
                var UserChannelHash = SocketDialogContextBase.GetHashCode(message.Channel, message.Author);
                //Check if there is an open dialog.
                //ToDo - If the hash logic is perfectly sound, we can remove the second check to improve performance.
                //This case, is outside of the channel type comparison, because a dialog can occur in many multiple channel types.
                if (this.Dialogs.ContainsKey(UserChannelHash) && this.Dialogs[UserChannelHash].InContext(message.Channel.Id, message.Author.Id))
                {
                    await this.Dialogs[UserChannelHash].ProcessMessage(message);
                }
                //Socket GUILD TEXT Channel.
                else if (message.Channel is SocketTextChannel tch)
                {
                    try
                    {
                        var cfg = await this.GuildRepo.GetConfig(tch.Guild);

                        #region Parse out command from prefix.
                        int  argPos    = 0;
                        bool HasPrefix = message.HasStringPrefix(cfg?.Prefix ?? "bot,", ref argPos, StringComparison.OrdinalIgnoreCase) ||
                                         message.HasMentionPrefix(Client.CurrentUser, ref argPos);
                        #endregion


                        //If the config is null, and we are not setting the environment, return.
                        if (cfg == null)
                        {
                            return;
                        }
                        //If the message was not to me, Ignore it.
                        else if (!HasPrefix)
                        {
                            return;
                        }

                        //Strip out the prefix.
                        string Msg = message.Content
                                     .Substring(argPos, message.Content.Length - argPos)
                                     .Trim()
                                     .RemovePrecedingChar(',');


                        //Load dynamic command context.
                        var context = new GuildCommandContext(Client, message, cfg, this);

                        var result = await commands.ExecuteAsync(context, Msg, kernel, MultiMatchHandling.Best);

                        //Return an error to the user, if we can send to this channel.
                        if (!result.IsSuccess && PermissionHelper.TestBotPermission(tch, Discord.ChannelPermission.SendMessages))
                        {
                            switch (result.Error.Value)
                            {
                            case CommandError.UnknownCommand:
                                break;

                            case CommandError.ParseFailed:
                                break;

                            case CommandError.BadArgCount:
                                break;

                            case CommandError.ObjectNotFound:
                                break;

                            case CommandError.MultipleMatches:
                                break;

                            case CommandError.UnmetPrecondition when result is AccessDeniedPreconditionResult access:
                                await tch.SendMessageAsync($"You do not have access to this command. You require the {access.RequiredRole.ToString()} role.");

                                break;

                            case CommandError.UnmetPrecondition when result is PreconditionResult res:
                                await tch.SendMessageAsync(res.ErrorReason);

                                break;

                            case CommandError.Exception:
                                await tch.SendMessageAsync("An error has occured. The details will be reported for remediation.");

                                break;

                            case CommandError.Unsuccessful:
                                break;
                            }
                        }

                        await Log.ChatMessage(message, tch.Guild, result);
                    }
                    catch (Exception ex)
                    {
                        await Log.Error(tch.Guild, ex);

                        return;
                    }
                }
                else if (message.Channel is SocketDMChannel dm)
                {
                    var context = new Core.ModuleType.CommandContext(Client, message, this);

                    var result = await commands.ExecuteAsync(context, message.Content, kernel, MultiMatchHandling.Best);
                }
            }
            catch (Exception ex)
            {
                await Log.Error(null, ex);
            }
        }
 public PollQuestionEntryDialog(GuildCommandContext context, TimeSpan Duration) : base(context)
 {
     this.duration = Duration;
     startStep(State.GET_QUESTION).Wait();
 }
 public PollQuestionEntryDialog(GuildCommandContext context, string question, TimeSpan Duration) : base(context)
 {
     this.Poll     = new Poll(context.Channel, question);
     this.duration = Duration;
     startStep(State.GET_OPTIONS).Wait();
 }