errbotio / errbot

Errbot is a chatbot, a daemon that connects to your favorite chat service and bring your tools and some fun into the conversation.
http://errbot.io
GNU General Public License v3.0
3.12k stars 612 forks source link

help about callback, start_poller() and command from bridge bot #1569

Closed ArchFeh closed 2 years ago

ArchFeh commented 2 years ago

Need help with

Issue description I wrote a callback function, it detacts in message whether exists bug xxxxxx, then do some search and return to channel or person. But it didn't work.

    def callback_message(self, mess):
        bug_list = re.findall('bug\s\d{6}', mess.body)
        if bug_list:
            URL = "https://bugs.gentoo.org/xmlrpc.cgi"
            bzapi = bugzilla.Bugzilla(URL)
            for i in bug_list:
                try:
                    bzapi.getbug(i.split(None)[1])
                except xmlrpc.client.Fault as err:
                    yield err
                else:
                    bug = bzapi.getbug(i.split(None)[1])
                    #self.send(mess.frm, "https://bugs.gentoo.org/" + str(i.split(None)[1]) + str(
                    #    bug.id) + bug.summary + bug.component + bug.status + bug.resolution)
                    #yield ("https://bugs.gentoo.org/" + str(i.split(None)[1]) + str(
                    #     bug.id) + bug.summary + bug.component + bug.status + bug.resolution)

The second question. I have a bridge bot in my irc channel, it bridge irc and telegram. When I send commands from telegram, the plugin doesn't work, because this bot add nickname before the command. So is there anyway to make it run?

FROM SERVER: :ervbot!~ervbot@user/ervbot PRIVMSG #PLCT-gentoo :[ArchFeh] !b update
2022-04-26 09:11:25,874 DEBUG    irc.client                _dispatcher: all_raw_messages
2022-04-26 09:11:25,875 DEBUG    irc.client                command: pubmsg, source: ervbot!~ervbot@user/ervbot, target: #bugler-test, arguments: ['[ArchFeh] !b update'], tags: None
2022-04-26 09:11:25,875 DEBUG    irc.client                _dispatcher: pubmsg
2022-04-26 09:11:25,875 DEBUG    errbot.core               *** frm = ervbot!~ervbot@user/ervbot
2022-04-26 09:11:25,876 DEBUG    errbot.core               *** username = ervbot
2022-04-26 09:11:25,876 DEBUG    errbot.core               *** text = [ArchFeh] !b update

The third question. start_poller() didn't work. I wrote a function to update database sqlite. I want start_poller() runs every 60s, but it didn't do anythig. It returned Previous timer found and removed

Thanks ahead!

Steps to reproduce Provide steps to reproduce the behavior or include sample plugin code.

Environment (please complete the following information):

Additional info If you have any more information, please specify it here.

nzlosh commented 2 years ago
  1. What didn't work? Do you have an error message?

  2. Perhaps triggering commands without prefixes could meet your needs https://errbot.readthedocs.io/en/latest/user_guide/plugin_development/botcommands.html?highlight=prefix#without-a-bot-prefix or alternatively, run a second errbot instance connected to the IRC server to expose commands within that scope.

  3. The log message Previous timer found and removed means the poller was scheduled correctly, what didn't work? Do you have an error message?

ArchFeh commented 2 years ago
  1. What didn't work? Do you have an error message?

  2. Perhaps triggering commands without prefixes could meet your needs https://errbot.readthedocs.io/en/latest/user_guide/plugin_development/botcommands.html?highlight=prefix#without-a-bot-prefix or alternatively, run a second errbot instance connected to the IRC server to expose commands within that scope.

  3. The log message Previous timer found and removed means the poller was scheduled correctly, what didn't work? Do you have an error message?

Thx for replying. For 1 and 3, there's no err message output. 1 just didn't send anything. In 3 there's a return or yield, and didn't send anything either. I will test without prefix tonight.

ArchFeh commented 2 years ago
  1. What didn't work? Do you have an error message?
  2. Perhaps triggering commands without prefixes could meet your needs https://errbot.readthedocs.io/en/latest/user_guide/plugin_development/botcommands.html?highlight=prefix#without-a-bot-prefix or alternatively, run a second errbot instance connected to the IRC server to expose commands within that scope.
  3. The log message Previous timer found and removed means the poller was scheduled correctly, what didn't work? Do you have an error message?

Thx, I figured out all my problems!

nzlosh commented 2 years ago

Would you mind sharing what caused the issues and how you resolved them? It may help others in the future or highlight deficiencies in the documentation.

ArchFeh commented 2 years ago

Sure. For 1 and 2 problem, I use without a bot prefix instead of callback_message(). For 3 problem, I found that in method can't use return or yield, if wanna send some messages to channel or user, use self.send(self.build_identifier("#channel") or self.send(self.build_identifier("nickname"), I think in callback has the same issue, we need use self.send to send message instead of return or yield. I use return and yield in my command to automatically check user or channel, and send message, but It can't be used in any callback.

nzlosh commented 2 years ago

Thank you for the feedback. :+1: