public override Task ExecuteAsync(string generator, WebHookHandlerContext context) { NameValueCollection nvc; if (context.TryGetData <NameValueCollection>(out nvc)) { string urlWithAccessToken = "https://hooks.slack.com/services/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"; SlackSend client = new SlackSend(urlWithAccessToken); string msg = ""; a = new developers { slackname = nvc["user_name"], lastpay = new date { day = "1", month = "1", year = "1" } }; string question = nvc["subtext"]; if (question == "yes") { breaklist.Add(a); tempbuuuulist.Remove(a); msg = "added " + breaklist.Count() + " " + tempbuuuulist.Count(); } else if (question == "no") { tempbuuuulist.Add(a); breaklist.Remove(a); msg = "removed " + breaklist.Count() + " " + tempbuuuulist.Count(); } else if (question == "status") { for (int i = 0; i < breaklist.Count(); i++) { msg += " " + breaklist[i].slackname + ""; } } else { Random rnd = new Random(); int num = rnd.Next(1, 7); if (num == 1) { msg = "pls .... Could you not"; } if (num == 2) { msg = "don't break me"; } if (num == 3) { msg = "I'm sorry " + a.slackname + ", i can't let you do that."; } if (num == 4) { msg = "leave breaky bot alone! :("; } if (num == 5) { msg = "Just what do you think you're doing, " + a.slackname + "?"; } if (num == 6) { msg = "we can talk about this"; } } msg += " " + a.slackname; SlackResponse reply = new SlackResponse(msg); context.Response = context.Request.CreateResponse(reply); } return(Task.FromResult(true)); }
public ActionResult finish() { //variables - end developers lastpayer = new developers(); developers lastpayer2 = new developers(); // incase 2 payers are needed ValueRange response2 = response; int i = 0; int j = 0; int attending = 0; SlackSend client = new SlackSend(urlWithAccessToken); //fin.update(breaklist , buuuulist); breaklist = fin.getBreakList(); buuuulist = fin.getBuuuuList(); for (int b = 0; b < temp.Count(); b++) { i = 0; for (int c = 0; c < breaklist.Count(); c++) { if (breaklist[c].slackname == temp[b].slackname) { breaklist[c] = temp[b]; } } } //we now have list of people going attending = breaklist.Count; i = 0; // find last person to pay if (attending != 0) { lastpayer = breaklist[i]; foreach (var cooldev in breaklist) { if (Int32.Parse(lastpayer.lastpay.year) >= Int32.Parse(breaklist[i].lastpay.year)) { if (Int32.Parse(lastpayer.lastpay.month) >= Int32.Parse(breaklist[i].lastpay.month)) { if (Int32.Parse(lastpayer.lastpay.day) > Int32.Parse(breaklist[i].lastpay.day)) { lastpayer = breaklist[i]; } } } i++; }// end foreach // if there more than 10 people attending find another person to help pay // the next person would be the next person who would pay if (breaklist.Count > 10) { foreach (var otherdev in breaklist) { j = 0; if (Int32.Parse(lastpayer2.lastpay.year) <= Int32.Parse(breaklist[j].lastpay.year)) { if (Int32.Parse(lastpayer2.lastpay.month) <= Int32.Parse(breaklist[j].lastpay.month)) { if (Int32.Parse(lastpayer2.lastpay.day) < Int32.Parse(breaklist[j].lastpay.day)) { if (lastpayer.slackname != breaklist[j].slackname) { lastpayer2 = breaklist[j]; } } } } j++; }// end foreach otherdev } // posting messages to channel on results of proccess client.PostMessage(text: "It is @" + lastpayer.slackname + " turn to pay", channel: "#breakfastmeet"); if (!(lastpayer2.slackname == null)) { client.PostMessage(text: "and @" + lastpayer2.slackname + " has to pay aswell\n because of too many people!", channel: "#breakfastmeet"); } client.PostMessage(text: "there are a total of " + attending + " people attending breakfast!", channel: "#breakfastmeet"); } else { client.PostMessage(text: "no breakky :(", channel: "#breakfastmeet"); } //start updating dates for google sheets docs for (i = 0; i < response.Values.Count(); i++) { if (response.Values[i][1].ToString() == lastpayer.slackname) { response.Values[i][2] = DateTime.Now.ToString("dd/MM/yyyy"); } if (lastpayer2.slackname != "") { if (response.Values[i][1].ToString() == lastpayer2.slackname) { response.Values[i][2] = DateTime.Now.ToString("dd/MM/yyyy"); } } } // update table with new last pay date of devs who just payed for breakfast string spreadsheetId2 = "1YMLuQ1tJnTJs1FQN0yruMHAS41nIRm1FHT87pP3GCV0"; string range2 = "Sheet1!A2:D14"; SpreadsheetsResource.ValuesResource.UpdateRequest request3 = service.Spreadsheets.Values.Update(response, spreadsheetId2, range2); // execute order 666 request3.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.RAW; request3.Execute(); client.PostMessage(text: "better luck next time", channel: "#breakfastmeet"); client.PostMessage(text: "Process: Stop", channel: "#breakfastmeet"); return(View()); }