s-nt-s / XmppBot

Xmpp Bot powered by Slixmpp
GNU General Public License v3.0
1 stars 1 forks source link

Allowing commands to be generators #3

Closed NikoMobile closed 1 year ago

NikoMobile commented 2 years ago

Hello,

I asked myself if it was possible create commands that would return multiple values and forked then modified your bot code to allow commands to be generators. It may be interesting

s-nt-s commented 2 years ago

Hello

I am not sure if I have understood your proposal but maybe you can do something like this:

import types

class MyBot(XmppBot):

    @botcmd
    def ping(self, *args, **kwargs):
        for i in range(5):
            yield "pong "+str(i)

    def reply_message(self, msg, txt, *args, **kwargs):
        if isinstance(txt, types.GeneratorType):
            for i in txt:
                super().reply_message(msg, i, *args, **kwargs)
        else:
            super().reply_message(msg, txt, *args, **kwargs)