示例#1
0
        protected override Task <ArgumentParseResult> ParseArgumentsGuildAsync(IGuildCommandContext context)
        {
            ArgumentContainer argOut = new ArgumentContainer();

            if (!ArgumentParsing.TryParseGuildTextChannel(context, context.Arguments.First, out argOut.channel))
            {
                return(Task.FromResult(new ArgumentParseResult(Arguments[0], "Failed to parse to a guild text channel!")));
            }

            if (context.Message.Content.Length > Identifier.Length + context.Arguments.First.Length + 2)
            {
                context.Arguments.Index++;
                string embedText = context.RemoveArgumentsFront(1).Replace("[3`]", "```");

                if (JSONContainer.TryParse(embedText, out JSONContainer json, out string errormessage))
                {
                    if (EmbedHelper.TryGetMessageFromJSONObject(json, out argOut.embed, out argOut.messageContent, out string error))
                    {
                        return(Task.FromResult(new ArgumentParseResult(argOut)));
                    }
                    else
                    {
                        return(Task.FromResult(new ArgumentParseResult(Arguments[1], error)));
                    }
                }
                else
                {
                    return(Task.FromResult(new ArgumentParseResult(Arguments[1], $"Unable to parse JSON text to a json data structure! Error: `{errormessage}`")));
                }
            }
示例#2
0
        protected override async Task <ArgumentParseResult> ParseArgumentsGuildAsync(IGuildCommandContext context)
        {
            MacroIdentifier = context.Arguments.First;

            if (!StoredMessagesService.IsValidMacroName(MacroIdentifier))
            {
                return(new ArgumentParseResult(Arguments[0], "Not a valid macro name!"));
            }

            context.Arguments.Index++;

            if (context.Arguments.First.ToLower() == "remove")
            {
                Delete        = true;
                SelectedMacro = null;
                return(ArgumentParseResult.SuccessfullParse);
            }
            else
            {
                Delete = false;
                JSONContainer json;
                if (context.Arguments.First.StartsWith("http"))
                {
                    string[] argSections = context.Arguments.First.Split("/", StringSplitOptions.RemoveEmptyEntries);
                    if (argSections.Length < 3)
                    {
                        return(new ArgumentParseResult(Arguments[1]));
                    }

                    if (!(ulong.TryParse(argSections[argSections.Length - 3], out ulong guildId) && ulong.TryParse(argSections[argSections.Length - 2], out ulong channelId) && ulong.TryParse(argSections[argSections.Length - 1], out ulong messageId)))
                    {
                        return(new ArgumentParseResult(Arguments[1]));
                    }

                    SocketGuild guild = BotCore.Client.GetGuild(guildId);
                    if (guild == null)
                    {
                        return(new ArgumentParseResult(Arguments[1]));
                    }

                    SocketTextChannel channel = guild.GetTextChannel(channelId);
                    if (channel == null)
                    {
                        return(new ArgumentParseResult(Arguments[1]));
                    }

                    IMessage message = await channel.GetMessageAsync(messageId);

                    if (message == null)
                    {
                        return(new ArgumentParseResult(Arguments[1]));
                    }

                    EmbedHelper.GetJSONFromUserMessage(message, out json);
                    SelectedMacro = new Macro(MacroIdentifier, json);
                }
                else
                {
                    string embedText = context.RemoveArgumentsFront(1).Replace("[3`]", "```");
                    if (!JSONContainer.TryParse(embedText, out json, out string error))
                    {
                        return(new ArgumentParseResult(Arguments[1]));
                    }

                    SelectedMacro = new Macro(MacroIdentifier, json);
                    if (!SelectedMacro.Build(out _, out _, out error))
                    {
                        return(new ArgumentParseResult(Arguments[1], error));
                    }
                }

                return(ArgumentParseResult.SuccessfullParse);
            }
        }
示例#3
0
        protected override async Task <ArgumentParseResult> ParseArgumentsGuildAsync(IGuildCommandContext context)
        {
            ArgumentContainer argOut = new ArgumentContainer();

            if (!context.Arguments.First.StartsWith("https://discordapp.com/channels/") || context.Arguments.First.Length < 40)
            {
                return(new ArgumentParseResult(Arguments[0], "Not a valid message link! Failed Startswith or length test"));
            }

            string[] messageIdentifiers = context.Arguments.First.Substring(32).Split('/');

            if (messageIdentifiers.Length != 3)
            {
                return(new ArgumentParseResult(Arguments[0], "Not a valid message link! Failed split test"));
            }

            if (!ulong.TryParse(messageIdentifiers[0], out ulong guildId) || !ulong.TryParse(messageIdentifiers[1], out ulong channelId) || !ulong.TryParse(messageIdentifiers[2], out ulong messageId))
            {
                return(new ArgumentParseResult(Arguments[0], "Not a valid message link! Failed id parse test"));
            }

            SocketGuild guild = BotCore.Client.GetGuild(guildId);

            if (guild != null)
            {
                SocketTextChannel channel = guild.GetTextChannel(channelId);

                if (channel != null)
                {
                    argOut.message = await channel.GetMessageAsync(messageId) as IUserMessage;

                    if (argOut.message == null)
                    {
                        return(new ArgumentParseResult(Arguments[0], "Found correct guild and correct channel, but not correct message! Has the message been deleted?"));
                    }
                    else if (argOut.message.Author.Id != BotCore.Client.CurrentUser.Id)
                    {
                        return(new ArgumentParseResult(Arguments[0], "Can not edit a message the bot didn't post itself"));
                    }
                }
                else
                {
                    return(new ArgumentParseResult(Arguments[0], "Found correct guild, but not the channel!"));
                }
            }
            else
            {
                return(new ArgumentParseResult(Arguments[0], "Could not find the correct guild!"));
            }

            if (context.Message.Content.Length > Identifier.Length + context.Arguments.First.Length + 2)
            {
                context.Arguments.Index++;
                string embedText = context.RemoveArgumentsFront(1).Replace("[3`]", "```");

                if (JSONContainer.TryParse(embedText, out JSONContainer json, out string errormessage))
                {
                    if (EmbedHelper.TryGetMessageFromJSONObject(json, out argOut.embed, out argOut.messageContent, out string error))
                    {
                        return(new ArgumentParseResult(argOut));
                    }
                    else
                    {
                        return(new ArgumentParseResult(Arguments[1], error));
                    }
                }
                else
                {
                    return(new ArgumentParseResult(Arguments[1], $"Unable to parse JSON text to a json data structure! Error: `{errormessage}`"));
                }
            }