コード例 #1
0
        public async Task getAllGlobal()
        {
            var file = StaticTextResponseService.getAllGlobalResponses();

            file.Seek(0, System.IO.SeekOrigin.Begin);
            await Context.Channel.SendFileAsync(file, "textresponse.json");
        }
コード例 #2
0
 public Task addGlobal(string key, [Remainder] string text)
 {
     try
     {
         StaticTextResponseService.addGlobalResponse(key, text);
     } catch (InvalidOperationException ex)
     {
         return(Context.Channel.SendMessageAsync(ex.Message));
     }
     return(Context.Channel.SendMessageAsync("OK"));
 }
コード例 #3
0
 public Task removeGlobal(string key)
 {
     try
     {
         StaticTextResponseService.removeGlobalResponse(key);
     }
     catch (InvalidOperationException ex)
     {
         return(Context.Channel.SendMessageAsync(ex.Message));
     }
     return(Context.Channel.SendMessageAsync("OK"));
 }
コード例 #4
0
        private async Task MessageReceived(SocketMessage rawMessage)
        {
            // Ignore system messages and messages from bots
            if (!(rawMessage is SocketUserMessage message))
            {
                return;
            }
            if (message.Source != MessageSource.User)
            {
                return;
            }
            var context = new SocketCommandContext(_discord, message);

            if (hasLatexMathQuotes(message.Content))
            {
                var    latexTypingState = context.Channel.EnterTypingState();
                string formattedLatex   = formatLatexString(message.Content);
                var    pictureService   = new PictureService(new System.Net.Http.HttpClient());
                var    image            = pictureService.GetLatexImage(formattedLatex).Result;
                image.Seek(0, SeekOrigin.Begin);
                await context.Channel.SendFileAsync(image, "latex.png");

                latexTypingState.Dispose();
            }

            if (featureToggleService.CheckFeature("auto-jfif-to-jpeg", context.Guild.Id.ToString()))
            {
                foreach (Attachment attachment in context.Message.Attachments)
                {
                    if (attachment.Filename.EndsWith(".jfif") || attachment.Filename.EndsWith(".JFIF") ||
                        attachment.Filename.EndsWith(".jfif-large"))
                    {
                        pictureService.ConvertJfifToJpeg(context, attachment.Url);
                    }
                }
            }

            int argPos = 0;

            if (!(message.HasMentionPrefix(_discord.CurrentUser, ref argPos) || message.HasStringPrefix(Program._config["prefix"] + " ", ref argPos)))
            {
                return;
            }


            //var typingState = context.Channel.EnterTypingState();
            var result = await _commands.ExecuteAsync(context, argPos, _provider);

            if (result.Error.HasValue &&
                result.Error.Value != CommandError.UnknownCommand)
            {
                await context.Channel.SendMessageAsync(result.ToString());

                return;
            }

            if (result.Error.HasValue &&
                result.Error.Value == CommandError.UnknownCommand)
            {
                string[] parts = message.Content.Split(' ');
                if (parts.Length >= 2)
                {
                    string textResponseLookup = parts[1];
                    Regex  userIdCheck        = new Regex(@"<@![0-9]+>", RegexOptions.Compiled);
                    if (userIdCheck.IsMatch(textResponseLookup))
                    {
                        textResponseLookup = textResponseLookup.Replace("!", string.Empty);
                    }

                    string response = StaticTextResponseService.getGlobalResponse(textResponseLookup)
                                      ?? staticTextResponseService.getResponse(context.Guild.Id, textResponseLookup);

                    if (response != null)
                    {
                        await context.Channel.SendMessageAsync(response);
                    }
                }
            }

            //typingState.Dispose();
        }