-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config options, adjust commands, console log
- Add new config options to Enable Slash Commands - Add and adjust commands for adding / removing channels, admins, and managers - New Console Mirror service to print out the console window to a Discord channel
- Loading branch information
Showing
44 changed files
with
1,738 additions
and
332 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
8 changes: 0 additions & 8 deletions
8
TModLoader/TerrariaChatRelay/Clients/DiscordClient/Helpers/DiscordMessage.cs
This file was deleted.
Oops, something went wrong.
82 changes: 0 additions & 82 deletions
82
TModLoader/TerrariaChatRelay/Clients/DiscordClient/Helpers/DiscordMessageQueue.cs
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
TModLoader/TerrariaChatRelay/Clients/DiscordClient/Messaging/DiscordMessage.cs
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,8 @@ | ||
namespace TerrariaChatRelay.Clients.DiscordClient.Messaging | ||
{ | ||
public class DiscordMessage | ||
{ | ||
public string Message { get; set; } | ||
public bool Embed { get; set; } | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
TModLoader/TerrariaChatRelay/Clients/DiscordClient/Messaging/DiscordMessageQueue.cs
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,82 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Timers; | ||
|
||
namespace TerrariaChatRelay.Clients.DiscordClient.Messaging | ||
{ | ||
public class DiscordMessageQueue : Dictionary<ulong, Queue<DiscordMessage>> | ||
{ | ||
public bool PreparingToSend { get { return preparingToSend; } } | ||
|
||
private bool preparingToSend { get; set; } | ||
private Timer queueTimer { get; set; } | ||
|
||
/// <summary> | ||
/// Initializes a new queue manager for Discord messages. | ||
/// </summary> | ||
/// <param name="QueueTime">Amount of time to queue messages before firing the OnReadyToSend event.</param> | ||
public DiscordMessageQueue(double QueueTime) | ||
{ | ||
preparingToSend = false; | ||
|
||
queueTimer = new Timer(QueueTime); | ||
queueTimer.Elapsed += delegate (object sender, ElapsedEventArgs e) | ||
{ | ||
PrepareSend(false); | ||
OnReadyToSend?.Invoke(this); | ||
Clear(); | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Queues message to add to send when queue is ready to send. | ||
/// </summary> | ||
/// <param name="channelToSendTo">Channel ID of target channel.</param> | ||
/// <param name="message">Message to send.</param> | ||
public void QueueMessage(ulong channelToSendTo, DiscordMessage message) | ||
=> QueueMessage(new List<ulong> { channelToSendTo }, message); | ||
|
||
/// <summary> | ||
/// Queues messages to add to send when queue is ready to send. | ||
/// </summary> | ||
/// <param name="channelToSendTo">Channel IDs of target channels.</param> | ||
/// <param name="message">Message to send.</param> | ||
public void QueueMessage(IEnumerable<ulong> channelsToSendTo, DiscordMessage message) | ||
{ | ||
foreach (var channelId in channelsToSendTo) | ||
{ | ||
if (!ContainsKey(channelId)) | ||
Add(channelId, new Queue<DiscordMessage>()); | ||
|
||
this[channelId].Enqueue(message); | ||
} | ||
|
||
PrepareSend(true); | ||
} | ||
|
||
/// <summary> | ||
/// Starts or stops the queue timer. | ||
/// </summary> | ||
/// <param name="Prepare"></param> | ||
private void PrepareSend(bool Prepare = true) | ||
{ | ||
if (Prepare && !preparingToSend) | ||
{ | ||
preparingToSend = true; | ||
queueTimer.Start(); | ||
} | ||
else if (!Prepare && preparingToSend) | ||
{ | ||
preparingToSend = false; | ||
queueTimer.Stop(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// <para>Fires when queue timer has elapsed. The timer begins when a message is queued. </para> | ||
/// If a message is queued while the timer is running, it will be queued. | ||
/// When the timer elapses, it will fire this event with a queue for each channel. | ||
/// </summary> | ||
public event Action<Dictionary<ulong, Queue<DiscordMessage>>> OnReadyToSend; | ||
} | ||
} |
85 changes: 0 additions & 85 deletions
85
TModLoader/TerrariaChatRelay/Clients/DiscordClient/Messaging/MessageQueue.cs
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
...TerrariaChatRelay/Clients/DiscordClient/Services/ConsoleMirror/ConsoleMirrorTextReader.cs
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,41 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace TerrariaChatRelay.Clients.DiscordClient.Services.ConsoleMirror | ||
{ | ||
/// <summary> | ||
/// Wraps the original Console TextWriter, intercepting output. | ||
/// </summary> | ||
internal class ConsoleMirrorTextReader : TextReader, IDisposable | ||
{ | ||
public event Action<String> ConsoleInputReceived; | ||
private TextReader previousReader { get; set; } | ||
|
||
public ConsoleMirrorTextReader(TextReader readerToWrap) | ||
{ | ||
previousReader = readerToWrap; | ||
} | ||
|
||
public override string ReadLine() | ||
{ | ||
string line = previousReader.ReadLine(); | ||
|
||
if (line != null) | ||
ConsoleInputReceived?.Invoke("> " + line); | ||
|
||
return line; | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
Console.SetIn(previousReader); | ||
base.Dispose(disposing); | ||
} | ||
|
||
base.Dispose(disposing); | ||
} | ||
} | ||
} |
Oops, something went wrong.