Esempio n. 1
0
        void RespondWithMoe(PrivateMessageEventArgs e, Post post, ChannelUser origin = null)
        {
            var sourceRegex = new Regex("\\[(?<source>.*)\\]"); // TODO: This doesn't work on titles like "foobar [Actual Source][Stupid Bullshit]"
            var source      = sourceRegex.Match(post.Title);
            var prefix      = "Here's a ";

            if (origin != null)
            {
                prefix = origin.Nick + " likes this ";
            }
            string response;

            if (!source.Success)
            {
                response = string.Format(prefix + "cute picture: {0}", post.Url);
            }
            else
            {
                var s = source.Groups["source"].Value;
                if (s.ToUpper() == "ORIGINAL")
                {
                    response = string.Format(prefix + "cute original picture: {0}", post.Url);
                }
                else
                {
                    response = string.Format(prefix + "cute picture from {0}: {1}", s, post.Url);
                }
            }
            Respond(e, response);
        }
Esempio n. 2
0
 internal void OnUserMessageReceived(PrivateMessageEventArgs e)
 {
     if (UserMessageReceived != null)
     {
         UserMessageReceived(this, e);
     }
 }
Esempio n. 3
0
        public async ValueTask PrivateMessageParse(object sender, PrivateMessageEventArgs eventArgs)
        {
            //配置文件实例
            config = new(eventArgs.LoginUid);
            //读取配置文件
            if (!config.LoadUserConfig(out UserConfig userConfig))
            {
                await eventArgs.Sender.SendPrivateMessage("读取配置文件(User)时发生错误\r\n请检查配置文件然后重启");

                ConsoleLog.Error("Qiushui机器人管理", "无法读取用户配置文件");
                return;
            }

            //人工智障
            //var service = new DealInstruction(ConsoleLog, userConfig);
            var all    = _keyWordServices.Query(t => t.ID > 0);
            var result = _keyWordServices.Query(t => t.Keys.Contains(eventArgs.Message.RawText)) ?? new List <LianKeyWords>();

            if (result.Count > 0 && result != null)
            {
                var strSb = new StringBuilder();
                strSb.Append($"已找到所有符合项:\r\n");
                foreach (var item in result)
                {
                    strSb.Append($"{item.Words}\r\n");
                }
                await eventArgs.Reply(strSb.ToString());
            }
            else
            {
                await eventArgs.Reply("没有找到任何符合要求记录");
            }
            //执行人工智障
            //await eventArgs.Reply("数据密码");
        }
Esempio n. 4
0
 internal void OnChannelMessageReceived(PrivateMessageEventArgs e)
 {
     if (ChannelMessageReceived != null)
     {
         ChannelMessageReceived(this, e);
     }
 }
    private void HandlePrivateMessage(PrivateMessageEventArgs args)
    {
        string accountId = args.AccountId;

        if (!m_PrivateMessages.ContainsKey(accountId))
        {
            m_PrivateMessages.Add
                (accountId, Instantiate(m_PrivateMessageBoxPrefab));

            m_PrivateMessages[accountId].transform.SetParent(m_MessageDisplayPanel.transform, false);

            m_PrivateMessages[accountId].GetComponent <PrivateMessageInstance>().
            InitializePrivateMessage(AccountManager.GetAccountById(accountId), args.Content, args.TimeStamp);

            if (!m_MessageNotifications.ContainsKey(accountId))
            {
                m_MessageNotifications.Add(accountId, Instantiate(m_MessageRepresenationPrefab));
                m_MessageNotifications[accountId].transform.SetParent(m_MessageNotificationPanel.transform, false);
                m_MessageNotifications[accountId].GetComponent
                <PrivateMessageButtonRepresenation>().SetPrivateMessageObject(m_PrivateMessages[accountId]);
            }
        }

        else if (m_PrivateMessages.ContainsKey(accountId))
        {
            m_PrivateMessages[accountId].GetComponent
            <PrivateMessageInstance>().AddTextToContent
                (args.Content, args.TimeStamp, AccountManager.GetAccountById(accountId));
        }
    }
Esempio n. 6
0
        /// <summary>
        /// Add a private message
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public PrivateMessage Add(PrivateMessage message)
        {
            // This is the message that the other user sees
            message = SanitizeMessage(message);
            message.DateSent = DateTime.UtcNow;
            message.IsSentMessage = false;

            var e = new PrivateMessageEventArgs { PrivateMessage = message };
            EventManager.Instance.FireBeforePrivateMessage(this, e);

            if (!e.Cancel)
            {
                message = _context.PrivateMessage.Add(message);

                // We create a sent message that sits in the users sent folder, this is
                // so that if the receiver deletes the message - The sender still has a record of it.
                var sentMessage = new PrivateMessage
                {
                    IsSentMessage = true,
                    DateSent = message.DateSent,
                    Message = message.Message,
                    UserFrom = message.UserFrom,
                    UserTo = message.UserTo
                };

                _context.PrivateMessage.Add(sentMessage);

                EventManager.Instance.FireAfterPrivateMessage(this, new PrivateMessageEventArgs { PrivateMessage = message });
            }

            // Return the main message
            return message;
        }
Esempio n. 7
0
 private void OnChannelMessageReceived(object sender, PrivateMessageEventArgs e)
 {
     foreach (var action in msgActions)
     {
         action(new BotMessageContext(this, client, e.PrivateMessage), e.PrivateMessage.Message);
     }
 }
Esempio n. 8
0
 void HandleChannelMessageRecieved(object sender, PrivateMessageEventArgs e)
 {
     if (e.PrivateMessage.Message.StartsWith(CommandPrefix + "seen"))
     {
         return;
     }
     using (var session = Program.Database.SessionFactory.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             var channel = session.Query <WormyChannel>().SingleOrDefault(c => c.Name == e.PrivateMessage.Source);
             var user    = session.Query <ChannelUser>().SingleOrDefault(u => u.Nick == e.PrivateMessage.User.Nick && u.Channels.Any(c => c == channel));
             if (user == null)
             {
                 user = new ChannelUser();
                 user.AddChannel(channel);
                 user.Nick = e.PrivateMessage.User.Nick;
             }
             user.LastSeen = DateTime.Now;
             user.LastSaid = e.PrivateMessage.Message;
             session.SaveOrUpdate(user);
             session.SaveOrUpdate(channel);
             transaction.Commit();
         }
     }
 }
Esempio n. 9
0
        void _chat_PrivateMessageEvent(Vha.Net.Chat chat, PrivateMessageEventArgs e)
        {
            // Check for ignores
            if (this.Ignores.Contains(e.Character))
            {
                return;
            }
            // Treat 'null-characters' as broadcasts
            if (e.CharacterID == 0)
            {
                this.Write(MessageClass.BroadcastMessage, e.Message);
                return;
            }
            // Dispatch message
            MessageSource source = new MessageSource(MessageType.Character, null, e.Character, e.Outgoing);

            this.Write(source, MessageClass.PrivateMessage, e.Message);
            // Add to recent friends
            Friend friend = this.GetFriend(e.Character);

            if (friend != null)
            {
                return;
            }
            this.Chat.SendFriendAdd(e.CharacterID, "\0");
        }
Esempio n. 10
0
 internal void OnPrivateMessageRecieved(PrivateMessageEventArgs e)
 {
     if (PrivateMessageRecieved != null)
     {
         PrivateMessageRecieved(this, e);
     }
 }
Esempio n. 11
0
 public void HandlePrivateMessageRecieved(object sender, PrivateMessageEventArgs e)
 {
     try
     {
         if (Program.Configuration.Irc.TrustedMasks.Any(e.PrivateMessage.User.Match))
         {
             if (e.PrivateMessage.Message.StartsWith("~"))
             {
                 // Handle command
                 var command    = e.PrivateMessage.Message.Substring(1);
                 var parameters = string.Empty;
                 if (command.Contains(" "))
                 {
                     parameters = command.Substring(command.IndexOf(' ') + 1);
                     command    = command.Remove(command.IndexOf(' '));
                 }
                 switch (command)
                 {
                 case "announce":
                     if (string.IsNullOrEmpty(parameters))
                     {
                         break;
                     }
                     Program.Announce(parameters);
                     break;
                 }
             }
         }
     }
     catch { }
 }
Esempio n. 12
0
        private static int EventPrivateMsg(int subType, int msgId, long fromQQ, IntPtr msg, int font)
        {
            PrivateMessageEventArgs args = new PrivateMessageEventArgs();

            args.MsgId   = msgId;
            args.FromQQ  = fromQQ;
            args.Msg     = NativeConvert.ToPtrString(msg, Encoding.GetEncoding("GB18030"));
            args.Handled = false;

            if (subType == 11)                  // 来自好友
            {
                ReceiveFriendMessage(null, args);
            }
            else if (subType == 1)              // 来自在线状态
            {
                ReceiveQnlineStatusMessage(null, args);
            }
            else if (subType == 2)              // 来自群
            {
                ReceiveGroupPrivateMessage(null, args);
            }
            else if (subType == 3)              // 来自讨论组
            {
                ReceiveDiscussPrivateMessage(null, args);
            }
            else
            {
                Common.CqApi.AddLoger(LogerLevel.Info, "Native提示", "EventPrivateMsg 方法发现新的消息类型");
            }

            return((int)(args.Handled ? MessageHanding.Intercept : MessageHanding.Ignored));            //如果处理过就截断消息
        }
Esempio n. 13
0
        private static void HandleMSG(PrivateMessageEventArgs e)
        {
            var sender  = e.PrivateMessage.User.Nick;
            var message = e.PrivateMessage.Message;
            var channel = e.PrivateMessage.Source;

            if (message.Equals($"{Config.IRC_CMDChar}uno"))
            {
                Game.StartGame(sender, channel);
            }

            if (message.Equals($"{Config.IRC_CMDChar}ujoin") || message.Equals($"{Config.IRC_CMDChar}uj"))
            {
                Game.AddPlayer(sender, channel);
            }

            if (sender == "lonely") // TODO remove this.
            {
                if (message.Equals($"{Config.IRC_CMDChar}testdeal"))
                {
                    GetCard.InitDeck();
                    Program.client.SendMessage(GetCard.DrawCards(7), channel);
                }
            }
        }
Esempio n. 14
0
 protected internal virtual void OnChannelMessageRecieved(PrivateMessageEventArgs e)
 {
     if (ChannelMessageRecieved != null)
     {
         ChannelMessageRecieved(this, e);
     }
 }
Esempio n. 15
0
        /// <summary>
        /// Type=21 在线状态消息
        /// </summary>
        /// <param name="sender">触发此事件的对象</param>
        /// <param name="e">附加的参数</param>
        public void ReceiveOnlineStatusMessage(object sender, PrivateMessageEventArgs e)
        {
            //本子程序会在酷Q【线程】中被调用,请注意使用对象等需要初始化(CoInitialize,CoUninitialize)。
            //这里处理消息

            e.Handled = false;  //关于返回说明, 请参见 "Event_ReceiveMessage.ReceiveFriendMessage" 方法
        }
Esempio n. 16
0
 protected internal virtual void OnUserMessageRecieved(PrivateMessageEventArgs e)
 {
     if (UserMessageRecieved != null)
     {
         UserMessageRecieved(this, e);
     }
 }
Esempio n. 17
0
        public override bool OnPrivateMessage(object sender, PrivateMessageEventArgs e)
        {
            if (base.OnPrivateMessage(sender, e))
            {
                return(true);
            }

            string message;

            // Don't relay the message if it's a ZNC 'not connected' notification.
            if (Regex.IsMatch(e.Message, @"^Your message to \S+ got lost"))
            {
                return(false);
            }

            // Don't relay the message if it's a command.
            Match match = Regex.Match(e.Message, @"^" + Regex.Escape(((IrcClient)sender).Me.Nickname) + @"\.*[:,-]? (.*)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                message = match.Groups[1].Value;
            }
            else
            {
                message = e.Message;
            }
            if (message.Length == 0 || !Bot.GetCommandPrefixes((IrcClient)sender, e.Sender.Nickname).Contains(message[0].ToString()))
            {
                this.SendCheck(string.Format("\u000315[\u000F{0}\u000315/\u000312PM\u000315] {1}{2}\u000F: {3}", (sender as IrcClient).NetworkName, Colours.NicknameColour(e.Sender.Nickname), e.Sender.Nickname, e.Message), (IrcClient)sender, e.Sender);
            }

            return(false);
        }
Esempio n. 18
0
 private void ChannelMessageRecieved(object sender, PrivateMessageEventArgs e)
 {
     Log($"P){e.PrivateMessage.Message}");
     //Log($"I){e.IrcMessage.RawMessage}");
     Log($"U){e.PrivateMessage.User.Nick}");
     Log($"S){e.PrivateMessage.Source}");
 }
Esempio n. 19
0
 /// <summary>
 /// 私聊处理
 /// </summary>
 public static async ValueTask PrivateMessageParse(object sender, PrivateMessageEventArgs privateMessage)
 {
     //简单的机器人响应
     if (privateMessage.Message.RawText.Equals("在"))
     {
         await privateMessage.Sender.SendPrivateMessage(CQCode.CQImage("https://i.loli.net/2020/11/02/2OgZ1M6YNV5kntS.gif"));
     }
 }
Esempio n. 20
0
 public LinkedIrcMessage(LinkedUser author, LinkedChannel channel, LinkedServer server, string message, PrivateMessageEventArgs privateMessageEventArgs)
 {
     this.author             = author;
     this.channel            = channel;
     this.server             = server;
     this.message            = message;
     PrivateMessageEventArgs = privateMessageEventArgs;
 }
Esempio n. 21
0
        /// <summary>
        /// Type=21 群私聊消息
        /// </summary>
        /// <param name="sender">触发此事件的对象</param>
        /// <param name="e">附加的参数</param>
        public void ReceiveGroupPrivateMessage(object sender, PrivateMessageEventArgs e)
        {
            //本子程序会在酷Q【线程】中被调用,请注意使用对象等需要初始化(CoInitialize,CoUninitialize)。
            //这里处理消息

            net.gensousakuya.dice.CommandCenter.Execute(e.Msg, net.gensousakuya.dice.EventSourceType.Private, e.FromQQ);

            e.Handled = false;  //关于返回说明, 请参见 "Event_ReceiveMessage.ReceiveFriendMessage" 方法
        }
        private void Client_OnPrivateMessage(object sender, PrivateMessageEventArgs e)
        {
            if (e.Message.Type == MessageType.Document && (e.Message.Document?.Filename ?? "").ToLower().EndsWith(".json"))
            {
                ProcessJsonDocument(e);
            }
            else if (e.Message.Location != null) // getting a location message, update the current raid
            {
                string state = ConversationManager.GetState(e.Message.From);
                if (state != "qe.state.expect.location")
                {
                    UpdateLocation(e.Message.From, e.Message.Location);
                    ShowMenu(e.Message.From);
                }
            }
            else
            {
                // the messaging client should probably support bot commands :-)
                // now we are happy with any help that the telegram servers give us anduse the detected entities
                var firstEntity = e.Message?.Entities?.FirstOrDefault();
                if (null != firstEntity && firstEntity.Type == "bot_command" && firstEntity.Offset == 0)
                {
                    string commandText = e.Message.Text.Substring(firstEntity.Offset, firstEntity.Length);
                    if (commandText == "/start")
                    {
                        ResetConversation(e.Message.From);
                        ShowMenu(e.Message.From);
                    }
                    if (commandText == "/team")
                    {
                        ResetConversation(e.Message.From);
                        Client.SendMessageToChat(e.Message.From.ID, _HTML_(I18N.GetString("Pick your team from the list.")), "HTML", true, true, null, CreateTeamMenu());
                    }
                    if (commandText == "/help")
                    {
                        Client.SendMessageToChat(e.Message.From.ID, _HTML_(I18N.GetString("Send a location from the telegram mobile client by pressing the paperclip button and selecting Location. Then drag the map so the position marker is at the location of the gym. The address information will automatically be added by the bot.\nAfter having sent the location, will out the remaining details.\nFinally, when you are ready, you can choose to either publish the raid to the public channel, or share your raid privately using the share-button.")), "HTML");
                    }
                }
                else
                {
                    string state = ConversationManager.GetState(e.Message.From);
                    switch (state)
                    {
                    case StateReadGym:
                        UpdateGym(e.Message.From, e.Message.Text);
                        ShowMenu(e.Message.From);
                        break;

                    case StateReadPokemon:
                        UpdateRaid(e.Message.From, e.Message.Text);
                        ShowMenu(e.Message.From);
                        break;
                    }
                }
            }
        }
Esempio n. 23
0
 private static async ValueTask Event_OnPrivateMessage(string type, PrivateMessageEventArgs eventArgs)
 {
     await MessageHandler.OnMessage(eventArgs.SoraApi, Utils.GetCQMessage(eventArgs.Message), new Source
     {
         Session   = eventArgs.SoraApi,
         FromGroup = 0,
         FromQQ    = eventArgs.SenderInfo.UserId,
         time      = eventArgs.Time
     });
 }
        /// <summary>
        /// Type=21 好友消息<para/>
        /// 处理收到的好友消息
        /// </summary>
        /// <param name="sender">事件的触发对象</param>
        /// <param name="e">事件的附加参数</param>
        public void ReceiveFriendMessage(object sender, PrivateMessageEventArgs e)
        {
            // 本子程序会在酷Q【线程】中被调用,请注意使用对象等需要初始化(CoInitialize,CoUninitialize)。
            // 这里处理消息

            e.Handled = false;
            // e.Handled 相当于 原酷Q事件的返回值
            // 如果要回复消息,请调用api发送,并且置 true - 截断本条消息,不再继续处理 //注意:应用优先级设置为"最高"(10000)时,不得置 true
            // 如果不回复消息,交由之后的应用/过滤器处理,这里置 false  - 忽略本条消息
        }
Esempio n. 25
0
        private void PrivateMessageHandler_PrivateMessageReceived(object sender, PrivateMessageEventArgs e)
        {
            PrivateMessageUser pmUser = privateMessageUsers.Find(u => u.IrcUser.Name == e.Sender);

            if (pmUser == null)
            {
                pmUser = new PrivateMessageUser(e.ircUser);
                privateMessageUsers.Add(pmUser);

                if (tabControl.SelectedTab == 0)
                {
                    string selecterUserName = string.Empty;

                    if (lbUserList.SelectedItem != null)
                    {
                        selecterUserName = lbUserList.SelectedItem.Text;
                    }

                    lbUserList.Clear();
                    privateMessageUsers.ForEach(pmsgUser => AddPlayerToList(pmsgUser.IrcUser,
                                                                            connectionManager.UserList.Find(u => u.Name == pmsgUser.IrcUser.Name) != null));

                    lbUserList.SelectedIndex = lbUserList.Items.FindIndex(i => i.Text == selecterUserName);
                }
            }

            ChatMessage message = new ChatMessage(e.Sender, otherUserMessageColor, DateTime.Now, e.Message);

            pmUser.Messages.Add(message);

            lastReceivedPMSender    = e.Sender;
            lastConversationPartner = e.Sender;

            if (!Visible)
            {
                HandleNotification(pmUser.IrcUser, e.Message);

                if (lbUserList.SelectedItem == null || lbUserList.SelectedItem.Text != e.Sender)
                {
                    return;
                }
            }
            else if (lbUserList.SelectedItem == null || lbUserList.SelectedItem.Text != e.Sender)
            {
                HandleNotification(pmUser.IrcUser, e.Message);
                return;
            }

            lbMessages.AddMessage(message);
            if (sndMessageSound != null)
            {
                sndMessageSound.Play();
            }
        }
Esempio n. 26
0
 protected internal virtual void OnUserMessageRecieved(PrivateMessageEventArgs e)
 {
     try
     {
         UserMessageRecieved(this, e);
     }
     catch (Exception err)
     {
         UnhandledException(this, new UnhandledExceptionEventArgs(err, false));
     }
 }
Esempio n. 27
0
 bool HandleUserMessage(PrivateMessageEventArgs e)
 {
     foreach (var mod in Modules)
     {
         if (mod.HandleUserMessage(e))
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 28
0
        /// <summary>
        /// Type=21 群私聊<para/>
        /// 处理收到的群私聊消息
        /// </summary>
        /// <param name="sender">事件的触发对象</param>
        /// <param name="e">事件的附加参数</param>
        public void ReceiveGroupPrivateMessage(object sender, PrivateMessageEventArgs e)
        {
            // 本子程序会在酷Q【线程】中被调用,请注意使用对象等需要初始化(CoInitialize,CoUninitialize)。
            // 这里处理消息
            e.Handled = LuaEnv.LuaEnv.RunLua(
                $"fromqq={e.FromQQ} " +
                $"message=[[{e.Msg.Replace("]", "] ")}]] " +
                $"id={e.MsgId}",
                "envent/ReceivePrivateMessage.lua");

            //e.Handled = false;  // 关于返回说明, 请参见 "Event_FriendMessage.ReceiveFriendMessage" 方法
        }
Esempio n. 29
0
 protected virtual void OnPrivateMessage(RemoteServer server, PrivateMessageEventArgs args)
 {
     PrivateMessageEvent?.Invoke(server, args);
     if (args.Sent)
     {
         PrivateMessageSentEvent?.Invoke(server, args);
     }
     else
     {
         PrivateMessageReceivedEvent?.Invoke(server, args);
     }
 }
Esempio n. 30
0
            protected virtual void RaiseEvent(PrivateMessageEventArgs args)
            {
                //temp copy : anti race conditions
                EventHandler <PrivateMessageEventArgs> eventRaiser = EventHandler;

                //null if no subs
                if (eventRaiser != null)
                {
                    //get a raise
                    eventRaiser(this, args);
                }
            }
Esempio n. 31
0
 internal bool HandleUserMessage(PrivateMessageEventArgs e)
 {
     foreach (var handler in RegexHandlers)
     {
         var matches = handler.Key.Matches(e.PrivateMessage.Message);
         if (matches.Count != 0)
         {
             handler.Value(e, matches);
         }
     }
     return(HandleMessage(UserCommandHandlers, e));
 }