Esempio n. 1
0
 public static void SendDirectMessage(string message, string username, string token)
 {
     try
     {
         Client client = new Client(token);
         client.PostMessage(message, "R3mus Bot", string.Concat("@", username));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        private void CrossPost(CRONJob settings)
        {
            if (settings.Enabled)
            {
                //Plugin.SendDirectMessage("Executing Jarvis", "clydeenmarland", Properties.Settings.Default.SlackWebhook);
                try
                {
                    var client = new Client {
                        UserName = Properties.Settings.Default.JarvisEmail,
                        Password = Properties.Settings.Default.JarvisPassword
                    };
                    if (client.Logon())
                    {
                        var messages = client.GetMessages(Properties.Settings.Default.JarvisDiscordRoom);

                        if (settings.LastRun == null)
                        {
                            messages = messages.OrderBy(msg => msg.timestamp).ToList();
                            messages.Where(msg => ((DateTime.Now - msg.timestamp).Days < 1) && (msg.content.Contains("To: coalition_pings"))).ToList().ForEach(msg =>
                            {
                                var senderlines = msg.content.Split(new[] { "\n" }, StringSplitOptions.None);

                                var payload = new MessagePayload();
                                //payload.Text = string.Format("@channel: From {0}", msg.author.username);
                                payload.Text = "@channel: Coalition Broadcast";
                                payload.Attachments = new List<MessagePayloadAttachment>();
                                payload.Attachments.Add(new MessagePayloadAttachment()
                                {
                                    Text = new Censor().CensorText(string.Join("\n", senderlines.Skip(1))),
                                    Title = string.Format("{0}", msg.timestamp.ToString("yyyy-MM-dd HH:mm:ss")),
                                    //Title = string.Format("{0}: Message from {1}", msg.timestamp.ToString("yyyy-MM-dd HH:mm:ss"), msg.author.username),
                                    Colour = "#ff6600"
                                });
                                Plugin.SendToRoom(payload, Properties.Settings.Default.JarvisSlackRoom, Properties.Settings.Default.SlackWebhook, msg.author.username);

                                foreach(var webhook in Properties.Settings.Default.DiscordLinkSlackWebhooks)
                                {
                                    Plugin.SendToRoom(payload, Properties.Settings.Default.JarvisSlackRoom, webhook, msg.author.username);
                                }
                            });
                        }
                        else
                        {
                            messages = messages.OrderBy(msg => msg.timestamp).ToList();
                            messages = messages.Where(msg =>
                            (msg.timestamp > settings.LastRun.Value
                            &&
                            (msg.content.Contains("To: coalition_pings"))
                            )).ToList();

                            messages.ForEach(msg =>
                            {
                                var senderlines = msg.content.Split(new[] { "\n" }, StringSplitOptions.None);
                                var payload = new MessagePayload();
                                //payload.Text = string.Format("@channel: From {0}", msg.author.username);
                                payload.Text = "@channel: Coalition Broadcast";
                                payload.Attachments = new List<MessagePayloadAttachment>();
                                payload.Attachments.Add(new MessagePayloadAttachment()
                                {
                                    Text = new Censor().CensorText(string.Join("\n", senderlines.Skip(1))),
                                    Title = string.Format("{0}", msg.timestamp.ToString("yyyy-MM-dd HH:mm:ss")),
                                    //Title = string.Format("{0}: Message from {1}", msg.timestamp.ToString("yyyy-MM-dd HH:mm:ss"), msg.author.username),
                                    Colour = "#ff6600"
                                });
                                Plugin.SendToRoom(payload, Properties.Settings.Default.JarvisSlackRoom, Properties.Settings.Default.SlackWebhook, msg.author.username);
                                foreach (var webhook in Properties.Settings.Default.DiscordLinkSlackWebhooks)
                                {
                                    Plugin.SendToRoom(payload, Properties.Settings.Default.JarvisSlackRoom, webhook, msg.author.username);
                                }
                            });
                        }
                        settings.LastRun = messages.LastOrDefault().timestamp.AddMilliseconds(-messages.LastOrDefault().timestamp.Millisecond).AddMinutes(1);

                        client.LogOut();
                    }
                }
                catch (Exception ex)
                {
                    //Plugin.SendDirectMessage(ex.Message, "clydeenmarland", Properties.Settings.Default.SlackWebhook);
                }
            }
        }
Esempio n. 3
0
 public static void SendToRoom(string message, string roomname, string token, string username)
 {
     try
     {
         Client client = new Client(token);
         client.PostMessage(message, username, string.Concat("#", roomname));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 4
0
        public static void SendDirectMessage(MessagePayload payload, string username, string token)
        {
            try
            {
                payload.Channel = string.Concat("@", username);
                payload.Username = "******";

                Client client = new Client(token);
                client.PostMessage(payload);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 5
0
        public static void SendToRoom(MessagePayload payload, string roomname, string token, string username)
        {
            try
            {
                payload.Channel = string.Concat("#", roomname);
                payload.Username = username;

                Client client = new Client(token);
                client.PostMessage(payload);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }