public void IrcPrivateMessage(object s, IrcMessageEventArgs e) { IrcLink.SendMessage( e.Message.Destination, $"{IrcMessageHelper.BoldText("Automated Message")}: {IrcMessageHelper.ItalicizeText("This user is a generated representation of a user connect to our Discord server. Private messages currently are no supported. Check back in the future!")}", e.Message.SourceUser); }
public void DiscordUserUpdated(object s, DiscordUserUpdatedEventArgs e) { var bridgeUser = UserLinks[e.Current.Username]; if (!DiscordUserConsideredOnline(e.Previous.Status) && DiscordUserConsideredOnline(e.Current.Status)) { IrcLink.SetAway(bridgeUser.IrcUid, false); } else if (DiscordUserConsideredOnline(e.Previous.Status) && !DiscordUserConsideredOnline(e.Current.Status)) { IrcLink.SetAway(bridgeUser.IrcUid, true); } // Join new channels foreach (var channel in e.NewChannels) { IrcLink.JoinChannel(bridgeUser.IrcUserName, Config.DiscordServer.ChannelMapping.FirstOrDefault(x => x.Discord == channel.Id)?.IRC); } // Leave removed channels foreach (var channel in e.RemovedChannels) { IrcLink.PartChannel(bridgeUser.IrcUserName, Config.DiscordServer.ChannelMapping.FirstOrDefault(x => x.Discord == channel.Id)?.IRC); } }
public void DiscordGuildConnected(object s, DiscordGuildConnectedEventArgs e) { if (e.Guild.Id == Config.DiscordServer.GuildId) { foreach (var channel in e.Guild.Channels) { var link = Config.DiscordServer.ChannelMapping.FirstOrDefault(x => x.Discord == channel.Id); if (link != null) { var users = channel.Users; foreach (var user in users.Where(x => !x.Roles.Select(y => y.Name).Intersect(Config.DiscordServer.IgnoredUserRoles).Any())) { JoinDiscordUserToIrcChannel(user, link); } } } foreach (var user in e.Guild.Users) { if (!DiscordUserConsideredOnline(user.Status) && UserLinks.ContainsKey(user.Username)) { UserLink thisLink = UserLinks[user.Username]; IrcLink.SetAway(thisLink.IrcUid, true); } } } }
private void PartDiscordUserFromIrcChannel(SocketGuildUser user, Channel link) { if (UserLinks.ContainsKey(user.Username)) { var thisLink = UserLinks[user.Username]; IrcLink.PartChannel(thisLink.IrcUserName, link.IRC); UserLinks.Remove(user.Username); } }
public void DiscordChannelMessage(object s, DiscordMessageEventArgs e) { var query = Config.DiscordServer.ChannelMapping.FirstOrDefault(x => x.Discord == e.Message.Channel.Id); if (query != null) { var thisLink = FindUserLink(e.Message.Author.Username); var parsedMessage = ParseDiscordMessage(e.Message.Content, e.Message.MentionedUsers); var isAction = parsedMessage.StartsWith(DiscordMessageHelper.ActionControl) && parsedMessage.EndsWith(DiscordMessageHelper.ActionControl); if (isAction) { parsedMessage = parsedMessage.DiscordToIrcAction(); } var chunkSize = Config.IRCServer.MaxMessageSize; if (parsedMessage.Length <= chunkSize) { if (isAction) { IrcLink.SendAction(thisLink.IrcUid, parsedMessage, query.IRC); } else { IrcLink.SendMessage(thisLink.IrcUid, parsedMessage, query.IRC); } } else { for (var i = 0; i < parsedMessage.Length; i += Config.IRCServer.MaxMessageSize) { if (i + Config.IRCServer.MaxMessageSize > parsedMessage.Length) { chunkSize = parsedMessage.Length - i; } var iterationMessage = parsedMessage.Substring(i, chunkSize); if (isAction) { IrcLink.SendAction(thisLink.IrcUid, iterationMessage, query.IRC); } else { IrcLink.SendMessage(thisLink.IrcUid, iterationMessage, query.IRC); } } } foreach (var attachment in e.Message.Attachments) { IrcLink.SendMessage(thisLink.IrcUid, $"{attachment.Url}", query.IRC); } } }
public async Task InitializeBridge(bool initIrc = true, bool initDiscord = true) { config = ConfigHelper.LoadConfig(); if (initIrc) { IrcLink = new IrcService(Logger, config.IRCServer); } if (initDiscord) { DiscordLink = new DiscordService(Logger, config.DiscordServer); } glue = new BridgeService(IrcLink, DiscordLink, config); if (initDiscord) { DiscordLink.OnChannelMessage += glue.DiscordChannelMessage; DiscordLink.OnGuildConnected += glue.DiscordGuildConnected; DiscordLink.OnUserUpdated += glue.DiscordUserUpdated; DiscordLink.OnUserJoin += glue.DiscordUserJoined; DiscordLink.OnUserLeave += glue.DiscordUserLeave; } if (initIrc) { IrcLink.OnChannelMessage += glue.IrcChannelMessage; IrcLink.OnPrivateMessage += glue.IrcPrivateMessage; IrcLink.OnServerDisconnect += glue.IrcServerDisconnect; IrcLink.OnServerConnect += glue.IrcServerConnect; } // Start the Async Processing if (initDiscord) { DiscordLink.MainAsync().GetAwaiter(); } if (initIrc) { IrcLink.StartBridge(); // Sort of Async.. Fix this later } }
private void JoinDiscordUserToIrcChannel(SocketGuildUser user, Channel link) { UserLink thisLink; if (UserLinks.ContainsKey(user.Username)) { thisLink = UserLinks[user.Username]; } else { thisLink = new UserLink(Config.IRCServer.NicknameSuffix) { BaseUserName = user.Username, DiscordUserName = user.Username, DiscordUserId = user.Id }; thisLink.IrcUid = IrcLink.RegisterNick(thisLink.IrcUserName); UserLinks.Add(user.Username, thisLink); } IrcLink.JoinChannel(thisLink.IrcUserName, link.IRC); }
public async Task Disconnect() { await IrcLink?.Disconnect(); await DiscordLink?.Disconnect(); }