예제 #1
0
 public void SendIrcMessage(string msg)
 {
     if (!Ready)
     {
         return;
     }
     IrcConnection.SendMessage(IrcConnection.Channel, msg);
 }
예제 #2
0
 public ChannelPair(IrcConnection ircConnection, DiscordConnectionInfo discordConnectionInfo)
 {
     this.DiscordConnectionInfo = discordConnectionInfo;
     this.IrcConnection         = ircConnection;
     this.EnableConsoleLogging  = true;
     this.Ready = false;
     this.IrcConnection.ConnectComplete += Irc_ConnectComplete;
     this.IrcConnection.MessageReceived += Irc_ChannelMessageReceived;
 }
예제 #3
0
 public void SendIrcMessage(string msg)
 {
     IrcConnection.SendMessage(IrcConnection.Channel, msg);
 }
예제 #4
0
 public ChannelPair(IrcConnection ircConnection, DiscordConnectionInfo discordConnectionInfo)
 {
     this.DiscordConnectionInfo = discordConnectionInfo;
     this.IrcConnection         = ircConnection;
     this.EnableConsoleLogging  = true;
 }
예제 #5
0
        private async Task Discord_MessageReceived(SocketMessage message)
        {
            if (message.Channel.Id != DiscordConnectionInfo.ChannelId || message.Author.Username == DiscordClient.CurrentUser.Username)
            {
                return;
            }

            if (EnableConsoleLogging)
            {
                Console.WriteLine($"#{message.Channel.Name}: [{message.Author.Username}] {message.Content}");
            }

            if (message.Content == "!ping")
            {
                await message.Channel.SendMessageAsync("Pong!");
            }
            else if (message.Content == "!ding")
            {
                await message.Channel.SendMessageAsync("Dong!");
            }
            else if (message.Content == "!online")
            {
                var users = IrcConnection.GetOnlineUsers();
                await message.Channel.SendMessageAsync("Users in IRC: ```" + string.Join(", ", users.Select(x => x.User.NickName).OrderBy(x => x)) + "```");
            }
            else if (message.Content.StartsWith("!say "))
            {
                if (IsDiscordUserAdmin(message.Author.Id))
                {
                    SendIrcMessage(message.Content.Split(' ', 2)[1]);
                }
                else
                {
                    await SendDiscordMessage("The 'say' command is only availble to administrators");
                }
            }
            else
            {
                var lines = message.Content.Split('\n').Select(x => x.Trim()).ToArray();
                for (int i = 0; i < Math.Min(lines.Length, 4); i++)
                {
                    var formattedMessage = $"<{message.Author.Username}> {lines[i]}";
                    foreach (var item in message.Tags)
                    {
                        switch (item.Type)
                        {
                        case TagType.ChannelMention:
                            formattedMessage = formattedMessage.Replace("<#" + item.Key + ">", "(#" + item.Value + ")");
                            break;

                        case TagType.RoleMention:
                            formattedMessage = formattedMessage.Replace("<@&" + item.Key + ">", "(@" + item.Value + ")");
                            break;

                        case TagType.UserMention:
                            formattedMessage = formattedMessage.Replace("<@" + item.Key + ">", "(@" + item.Value + ")");
                            break;
                        }
                    }
                    SendIrcMessage(formattedMessage);
                    foreach (var item in message.Attachments)
                    {
                        SendIrcMessage($"* {message.Author.Username} attached file '{item.Filename}': {item.Url}");
                    }
                }
                if (lines.Length > 4)
                {
                    SendIrcMessage($"({message.Author.Username} posted {lines.Length - 5} more lines not shown here)");
                }
            }
        }