-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
335 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using golf1052.SlackAPI; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace botbot.Module | ||
{ | ||
public class HubotModule : SlackEventModule | ||
{ | ||
private readonly HttpClient httpClient; | ||
private readonly string baseUrl; | ||
|
||
public HubotModule(SlackCore slackCore, Func<string, Task> SendMessage) : base(slackCore, SendMessage) | ||
{ | ||
httpClient = new HttpClient(); | ||
baseUrl = $"http://localhost:{Secrets.HubotPortNumber}"; | ||
} | ||
|
||
public override async Task Handle(string type, JObject e) | ||
{ | ||
if (type == "hello") | ||
{ | ||
} | ||
else if (type == "goodbye") | ||
{ | ||
} | ||
else | ||
{ | ||
JObject requestObject = new JObject(); | ||
requestObject["slack"] = e; | ||
SendHubot("slack", requestObject); | ||
} | ||
} | ||
|
||
public async Task Init(string token) | ||
{ | ||
JObject requestObject = new JObject(); | ||
requestObject["token"] = token; | ||
await SendHubot("init", requestObject); | ||
} | ||
|
||
private async Task SendHubot(string type, JObject requestObject) | ||
{ | ||
requestObject["type"] = type; | ||
try | ||
{ | ||
HttpResponseMessage responseMessage = await httpClient.PostAsync(baseUrl, new StringContent(requestObject.ToString(), Encoding.UTF8, "application/json")); | ||
if (!responseMessage.IsSuccessStatusCode) | ||
{ | ||
// maybe log? | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
// if hubot is down don't really worry about it | ||
} | ||
} | ||
|
||
public override RecurringModule RegisterRecurring() | ||
{ | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace botbot.Module | ||
{ | ||
public interface IEventModule | ||
{ | ||
Task Handle(string type, JObject e); | ||
|
||
RecurringModule RegisterRecurring(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace botbot.Module | ||
{ | ||
public class RecurringModule | ||
{ | ||
public TimeSpan Interval { get; private set; } | ||
|
||
public Func<Task> Func { get; private set; } | ||
|
||
public RecurringModule(TimeSpan interval, Func<Task> func) | ||
{ | ||
Interval = interval; | ||
Func = func; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using golf1052.SlackAPI; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace botbot.Module | ||
{ | ||
public abstract class SlackEventModule : IEventModule | ||
{ | ||
protected readonly SlackCore slackCore; | ||
protected readonly Func<string, Task> SendMessageFunc; | ||
|
||
public SlackEventModule(SlackCore slackCore, Func<string, Task> SendMessage) | ||
{ | ||
this.slackCore = slackCore; | ||
SendMessageFunc = SendMessage; | ||
} | ||
|
||
public abstract Task Handle(string type, JObject e); | ||
|
||
public abstract RecurringModule RegisterRecurring(); | ||
} | ||
} |
Oops, something went wrong.