1- using Newtonsoft . Json ;
2- using Perpetuum . Accounting . Characters ;
1+ using Perpetuum . Accounting . Characters ;
32using Perpetuum . Common . Loggers ;
43using Perpetuum . Host . Requests ;
54using Perpetuum . Services . Channels . ChatCommands ;
5+ using Perpetuum . Services . EventServices ;
6+ using Perpetuum . Services . EventServices . EventMessages ;
67using Perpetuum . Services . Sessions ;
78using System ;
89using System . Collections . Concurrent ;
910using System . Collections . Generic ;
1011using System . Linq ;
11- using System . Net . Http ;
12- using System . Text ;
1312using System . Threading ;
14- using System . Threading . Tasks ;
1513
1614namespace Perpetuum . Services . Channels
1715{
@@ -27,6 +25,7 @@ public class ChannelManager : IChannelManager
2725 private readonly ConcurrentDictionary < string , Channel > _channels = new ConcurrentDictionary < string , Channel > ( ) ;
2826 private readonly AdminCommandRouter _adminCommand ;
2927 private readonly GlobalConfiguration _globalConfiguration ;
28+ private readonly EventListenerService _eventChannel ;
3029
3130 public ChannelManager (
3231 ISessionManager sessionManager ,
@@ -35,6 +34,7 @@ public ChannelManager(
3534 IChannelBanRepository banRepository ,
3635 ChannelLoggerFactory channelLoggerFactory ,
3736 AdminCommandRouter adminCommand ,
37+ EventListenerService eventListener ,
3838 GlobalConfiguration globalConfiguration )
3939 {
4040 _sessionManager = sessionManager ;
@@ -51,6 +51,7 @@ public ChannelManager(
5151 _channels [ channel . Name ] = channel ;
5252 }
5353
54+ _eventChannel = eventListener ;
5455 _globalConfiguration = globalConfiguration ;
5556 }
5657
@@ -313,6 +314,17 @@ public void Talk(string channelName, Character sender, string message, IRequest
313314 {
314315 channel . SendMessageToAll ( _sessionManager , sender , message ) ;
315316
317+ if ( channel . DiscordId != null )
318+ {
319+ _eventChannel . PublishMessage (
320+ new DiscordIntegrationMessage (
321+ EventType . PerpetuumToDiscord ,
322+ channel . DiscordId . Value ,
323+ sender . Nick ,
324+ message ) ) ;
325+ }
326+
327+ /*
316328 if (channel.Name == HelpChat)
317329 {
318330 // Sending message to discord
@@ -340,6 +352,7 @@ public void Talk(string channelName, Character sender, string message, IRequest
340352 HttpResponseMessage response = await httpClient.PostAsync(url, content);
341353 });
342354 }
355+ */
343356 }
344357 }
345358
@@ -461,11 +474,17 @@ public IEnumerable<Channel> GetAllChannels()
461474 {
462475 return _channels . Values ;
463476 }
477+
478+ public string GetChannelNameByDiscordId ( ulong discordId )
479+ {
480+ return _channels . FirstOrDefault ( x => x . Value . DiscordId . GetValueOrDefault ( ) == discordId ) . Key ;
481+ }
464482 }
465483
466484 internal class DiscordPayload
467485 {
468- public DateTime Timestamp { get ; set ; }
469486 public string content { get ; set ; }
487+
488+ public object allowed_mentions { get ; } = new { parse = new [ ] { "users" } } ;
470489 }
471490}
0 commit comments