private void MessageCallBack(object sender, Message msg, object data) { if (msg.Body != null) { var payload = new MessagePayload(); payload.Attachments = new List<MessagePayloadAttachment>(); if (!msg.Body.Contains("@everyone")) { msg.Body = string.Concat("@everyone: ", msg.Body); } payload.Attachments.Add(new MessagePayloadAttachment() { Text = msg.Body.Replace("@everyone", "@channel"), Title = string.Format("{0}: Message from {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "Marvin"), Colour = "#ff0066" }); Plugin.SendToRoom(payload, Properties.Settings.Default.FleetRoomName, Properties.Settings.Default.SlackWebhook, Properties.Settings.Default.FleetBotName); if (msg.Body.Contains("bog_all")) { foreach (var hook in Properties.Settings.Default.DiscordLinkSlackWebhooks) { Plugin.SendToRoom(payload, Properties.Settings.Default.FleetRoomName, hook, Properties.Settings.Default.FleetBotName); } } } }
//Post a message using simple strings internal void PostMessage(string v_Message, string v_Username = null, string v_Channel = null) { MessagePayload payload = new MessagePayload() { Channel = v_Channel, Username = v_Username, Text = v_Message }; PostMessage(payload); }
//Post a message using a Payload object internal void PostMessage(MessagePayload payload) { string payloadJson = JsonConvert.SerializeObject(payload); using (WebClient client = new WebClient()) { NameValueCollection data = new NameValueCollection(); data["payload"] = payloadJson; var response = client.UploadValues(uri, "POST", data); //The response text is usually "ok" string responseText = encoding.GetString(response); } }
//Post a message using a Payload object internal void PostMessage(MessagePayload payload) { string payloadJson = JsonConvert.SerializeObject(payload); using (WebClient client = new WebClient()) { NameValueCollection data = new NameValueCollection(); data["payload"] = payloadJson; var response = client.UploadValues(uri, "POST", data); //The response text is usually "ok" string responseText = encoding.GetString(response); } }
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; } }
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; } }
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; } }
private static void SendPM(MessagePayload message) { if (Properties.Settings.Default.Plugin.ToUpper() == "HIPCHAT") { //Hipchat.SendPM(message, Properties.Settings.Default.HipchatToken, "Clyde en Marland"); } else if (Properties.Settings.Default.Plugin.ToUpper() == "SLACK") { Plugin.SendDirectMessage(message, "ClydeenMarland", Properties.Settings.Default.SlackWebhook); } }
private static void SendLossMessage(MessagePayload message) { if (Properties.Settings.Default.Plugin.ToUpper() == "HIPCHAT") { //Hipchat.SendToRoom(message, Properties.Settings.Default.RoomName, Properties.Settings.Default.HipchatToken); } else if (Properties.Settings.Default.Plugin.ToUpper() == "SLACK") { //message = Linkify(message); Plugin.SendToRoom(message, Properties.Settings.Default.LossRoomName, Properties.Settings.Default.SlackWebhook, Properties.Settings.Default.BotName); } }
static void Main(string[] args) { if ((args.Length > 0) && (args[0].Contains("lol"))) { args.ToList().Skip(1).ToList().ForEach(arg => { try { SendLossMessage(HyperFormatLolMessage(arg)); } catch (Exception ex) { SendPM(ex.Message); } }); } else { try { MessagePayload p = new MessagePayload(); p.Attachments = new List<MessagePayloadAttachment>(); if ((Properties.Settings.Default.CorpId == null) || (Properties.Settings.Default.CorpId == string.Empty)) { CorporationSheet corpSheet = GetCorpDetails(); if (Properties.Settings.Default.Debug) { SendPM(string.Format("Corpsheet for {0} obtained.", corpSheet.Ticker)); } CheckKills(corpSheet.Ticker, corpSheet.CorporationID); } else { CheckKills(Properties.Settings.Default.CorpTicker, Convert.ToInt64(Properties.Settings.Default.CorpId)); } } catch (Exception ex) { SendPM(ex.Message); } } }
private static MessagePayload HyperFormatLolMessage(string name) { MessagePayload message = new MessagePayload(); message.Attachments = new List<MessagePayloadAttachment>(); string type; List<string> messageLines = new List<string>(); type = "KILL"; string killTitle = string.Format(Properties.Settings.Default.MessageFormatLine1, "R3MUS", type, DateTime.Now.AddMinutes(-10).ToString()); //messageLines.Add(killTitle); string killLine1 = string.Format("{0} lost a capsule", name, "", "Jita", "The Forge"); messageLines.Add(killLine1); messageLines.Add(string.Format(Properties.Settings.Default.MessageFormatLine3, "The Mittani", "Procurer")); messageLines.Add(string.Format(Properties.Settings.Default.MessageFormatLine4, "stelios102", "Venture")); messageLines.Add(string.Format(Properties.Settings.Default.MessageFormatLine4, "Vas Enyo", "Gallente Shuttle")); messageLines.Add(string.Format(Properties.Settings.Default.MessageFormatLine5, "200,000,000")); messageLines.Add(string.Empty); message.Attachments.Add(new MessagePayloadAttachment() { Text = String.Join("\n", messageLines.ToArray()), TitleLink = "http://www.troll.me/images/pissed-off-obama/you-have-been-pwned-by-the-troll-king.jpg", Title = killTitle, ThumbUrl = string.Empty }); if (type == "KILL") { message.Attachments.First().Colour = "#00FF00"; } else if (type == "LOSS") { message.Attachments.First().Colour = "#FF0000"; } return message; }
private static MessagePayload HyperFormatKillMessage(ZkbResponse.ZkbKill kill, string corpName, long corpId) { MessagePayload message = new MessagePayload(); message.Attachments = new List<MessagePayloadAttachment>(); string type; List<string> messageLines = new List<string>(); if (kill.Victim.CorporationId == corpId) { type = "LOSS"; } else { type = "KILL"; } EveAI.Map.SolarSystem system = GetSolarSystem(kill.SolarSystemId); ZkbResponse.ZkbStats stats = kill.Stats; string killTitle = string.Format(Properties.Settings.Default.MessageFormatLine1, corpName, type, kill.KillTime.ToString()); //messageLines.Add(killTitle); string killLine1 = string.Format(Properties.Settings.Default.MessageFormatLine2, kill.Victim.CharacterName, GetProductType(kill.Victim.ShipTypeId).Name, system.Name, system.Region.Name); messageLines.Add(killLine1); foreach (ZkbResponse.ZkbAttacker Attacker in kill.Attackers) { if (Attacker.FinalBlow == true) { messageLines.Add(string.Format(Properties.Settings.Default.MessageFormatLine3, Attacker.CharacterName, GetProductType(Attacker.ShipTypeId).Name)); } } foreach (ZkbResponse.ZkbAttacker Attacker in kill.Attackers) { if (Attacker.CorporationId == corpId) { messageLines.Add(string.Format(Properties.Settings.Default.MessageFormatLine4, Attacker.CharacterName, GetProductType(Attacker.ShipTypeId).Name)); } } if (stats != null) { messageLines.Add(string.Format(Properties.Settings.Default.MessageFormatLine5, stats.TotalValue.ToString("N2"))); } string killUrl = string.Format(Properties.Settings.Default.KillURL, kill.KillId.ToString()); messageLines.Add(string.Empty); message.Attachments.Add(new MessagePayloadAttachment() { Text = String.Join("\n", messageLines.ToArray()), TitleLink = killUrl, Title = killTitle, ThumbUrl = string.Format(Properties.Settings.Default.ShipImageUrl, kill.Victim.ShipTypeId.ToString()) }); if(type == "KILL") { message.Attachments.First().Colour = "#00FF00"; } else if (type == "LOSS") { message.Attachments.First().Colour = "#FF0000"; } return message; }
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); } } }
public ActionResult SubmitSuggestion(FormCollection form) { try { MessagePayload message = new MessagePayload(); message.Attachments = new List<MessagePayloadAttachment>(); message.Attachments.Add(new MessagePayloadAttachment() { Text = form["SuggestionText"].ToString(), Title = "Begging your pardons, Sirs & Madams, but might I make a suggestion?", ThumbUrl = "http://www.r3mus.org/Images/kryten.png" }); Plugin.SendToRoom(message, Properties.Settings.Default.SuggestionRoomName, Properties.Settings.Default.SlackWebhook, "Kryten"); TempData.Add("Message", "Thank you for your input."); } catch (Exception ex) { TempData.Add("Message", ex.Message); ModelState.AddModelError("Error1", ex.Message); } return RedirectToAction("Index"); }
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; } }