コード例 #1
0
        private static void ServerManager_OnPOSTRequest(JArray jArray)
        {
            MessageBuilder messageBuilder = new MessageBuilder();

            foreach (var item in jArray)
            {
                PluginRequestObject pluginRequestObject = item.ToObject <PluginRequestObject>();
                messageBuilder.AddMessage(new ChatRoomInfo(pluginRequestObject.Guild, pluginRequestObject.Channel), pluginRequestObject.Msg);
            }

            foreach (var item in messageBuilder.Messages)
            {
                string fullcontent = item.Value.ToString();
                int    chunkSize   = 2000;
                for (int i = 0; i < fullcontent.Length; i += chunkSize)
                {
                    while (true)
                    {
                        try
                        {
                            (DiscordServer?.DiscordSocketClient?
                             .GetGuild(item.Key.Guild)?
                             .GetChannel(item.Key.Channel) as ISocketMessageChannel)?
                            .SendMessageAsync(fullcontent.Substring(i, (fullcontent.Length < i + chunkSize) ? fullcontent.Length - i : chunkSize))?.Wait();
                        }
                        catch (System.AggregateException)
                        {
                            continue;
                        }
                        break;
                    }
                }
            }
        }