Exemplo n.º 1
0
 async def onMessage(self, ctx):
     msg = ctx.msg
     args = parse_args(ctx.content)
     if args[0].startswith(prefix):
         args.insert(0, args[0].replace(prefix, ""))
         args.pop(1)
         for name, info in commands.items():
             if args[0] == name:
                 try:
                     await info["handler"](ctx, args)
                 except Exception as e:
                     print(f"Error in command {name}.")
                     print_exc()
             for alias in info["aliases"]:
                 if args[0] == alias:
                     try:
                         await info["handler"](ctx, args)
                     except Exception as e:
                         print(f"Error in command {name}.")
                         print_exc()
                 continue
Exemplo n.º 2
0
                self.creator_addr.put(Txn.sender()),
                Return(Int(1)),
            ]
        )


if __name__ == "__main__":
    params = {
        "ratio_decimal_points": 1000000,
        "fee_pct": 3,
        "type": ExchangeType.ALGOS_TO_ASA,
    }

    # Overwrite params if sys.argv[1] is passed
    if len(sys.argv) > 1:
        params = parse_args(sys.argv[1], params)

    if params["type"] == ExchangeType.ALGOS_TO_ASA:
        print(
            compileTeal(
                AlgosToAsaContract(
                    int(params["ratio_decimal_points"]),
                    int(params["fee_pct"]),
                ).get_contract(),
                Mode.Application,
            )
        )
    elif params["type"] == ExchangeType.ASA_TO_ASA:
        print(
            compileTeal(
                AsaToAsaContract(
Exemplo n.º 3
0
    async def onMessage(self, msg: osu_irc.Message):
        if msg.room_name.startswith("mp_"):
            global games_open
            mp_id = re.findall(r"mp_([0-9]+)", msg.room_name)[0]
            for game in games_open:
                if game.mp_id == int(mp_id):
                    user = await api.get_user(msg.user_name)
                    ctx = Classify({  # context object to send to command
                        "message": msg,  # message object
                        "msg": msg,  # alias to message
                        "username": msg.user_name,
                        "content":
                        msg.content,  # raw message contents (not parsed)
                        "userid": user.user_id,
                        "bot": self,
                        "match": game
                    })
                    if msg.user_name == "BanchoBot":
                        await game.onMultiEvent(ctx)
                    else:
                        await game.onMessage(ctx)
            return

        if msg.is_private:
            banned = await get_banned(msg.user_name)
            print(msg.content)
            args = parse_args(msg.content)
            user = await api.get_user(msg.user_name)

            if msg.user_name == "BanchoBot":
                if msg.content.startswith("You cannot create any more"):
                    return  # too many tournament matches created by bot
                global recent_mp_id
                mp_id = int(
                    re.findall(
                        r"Created the tournament match https:\/\/osu\.ppy\.sh\/mp\/([0-9]+)",
                        msg.content)[0])
                recent_mp_id = mp_id
                return

            ctx = Classify({  # context object to send to command
                "message": msg,  # message object
                "msg": msg,  # alias to message
                "username": msg.user_name,
                "content": msg.content,  # raw message contents (not parsed)
                "userid": user.user_id,
                "bot": self,
                "match": None
            })
            responce = await parse_commands(args, ctx)

            # !commands
            if responce:  # only send if command detected

                @RateLimiter(max_calls=10, period=5)  # user rate limits
                async def send_msg():
                    await add_user(msg.user_name, user.user_id,
                                   msg.content)  # add user to db
                    await log_command(msg.user_name, user.user_id,
                                      msg.content)  # log the message

                    if banned:
                        return
                    else:
                        r = responce

                    await self.sendPM(msg.user_name, str(r))
                    print(f"Sent {msg.user_name} this \"{r}\"")  # debugging

                await send_msg()
                return

            # /np
            elif msg.content.startswith("is "):
                user = await api.get_user(msg.user_name)

                print(
                    f"Got /np from {msg.user_name} which contains this \"{msg.content}\""
                )
                await log_command(msg.user_name, user.user_id, msg.content)

                # get /np
                await add_user(msg.user_name, user.user_id, msg.content)

                all = re.findall(
                    r"is playing \[https:\/\/osu\.ppy\.sh\/beatmapsets\/[0-9]+\#(.*)\/([0-9]+) .*\]( .*|)|is listening to \[https:\/\/osu\.ppy\.sh\/beatmapsets\/[0-9]+\#(.*)\/([0-9]+) .*\]|is editing \[https:\/\/osu\.ppy\.sh\/beatmapsets\/[0-9]+\#(.*)\/([0-9]+) .*\]|is watching \[https:\/\/osu\.ppy\.sh\/beatmapsets\/[0-9]+\#(.*)\/([0-9]+) .*\]( .*|)",
                    str(msg.content))

                mods, map_id = process_re(all)

                await set_last_beatmap(msg.user_name, map_id)

                mode = await api.get_beatmap(beatmap_id=map_id)

                result = await pp(map_id, mods, mode.mode)

                for r in result.split("\n"):
                    await self.sendPM(msg.user_name, r)

            # other message, try to detect easter egg phrase
            else:
                phrase = check_phrase(msg.content)
                if phrase:
                    await self.sendPM(msg.user_name, phrase)
Exemplo n.º 4
0
async def onMessage(msg: osu_irc.Message):
    banned = await get_banned(msg.user_name)
    if msg.is_private:
        args = parse_args(msg.content)
        user = await api.get_user(msg.user_name)

        if msg.user_name == "BanchoBot":
            if msg.content.startswith("You cannot create any more"):
                return
            global recent_mp_id
            mp_id = int(
                re.findall(
                    r"Created the tournament match https:\/\/osu\.ppy\.sh\/mp\/([0-9]+)",
                    msg.content)[0])
            recent_mp_id = mp_id
            return

        ctx = Classify({  # context object to send to command
            "message": msg,  # message object
            "msg": msg,  # alias to message
            "username": msg.user_name,
            "content": msg.content,  # raw message contents (not parsed)
            "userid": user.user_id,
            "match": None
        })
        responce = await parse_commands(args, ctx)
        if responce:  # only send if command detected

            async def send_msg():
                await add_user(msg.user_name, user.user_id,
                               msg.content)  # add user to db
                await log_command(msg.user_name, user.user_id,
                                  msg.content)  # log the message

                print(f"TEST Sent {msg.user_name} this \"{responce}\"")
                return str(responce)

            r = await send_msg()
            return r
        if msg.content.startswith("is "):
            user = await api.get_user(msg.user_name)

            print(
                f"Got /np from {msg.user_name} which contains this \"{msg.content}\""
            )
            await log_command(msg.user_name, user.user_id, msg.content)

            # get /np
            await add_user(msg.user_name, user.user_id, msg.content)

            all = re.findall(
                r"is playing \[https:\/\/osu\.ppy\.sh\/beatmapsets\/[0-9]+\#(.*)\/([0-9]+) .*\]( .*|)|is listening to \[https:\/\/osu\.ppy\.sh\/beatmapsets\/[0-9]+\#(.*)\/([0-9]+) .*\]|is editing \[https:\/\/osu\.ppy\.sh\/beatmapsets\/[0-9]+\#(.*)\/([0-9]+) .*\]|is watching \[https:\/\/osu\.ppy\.sh\/beatmapsets\/[0-9]+\#(.*)\/([0-9]+) .*\]( .*|)",
                str(msg.content))

            mods, map_id = process_re(all)

            await set_last_beatmap(msg.user_name, map_id)

            mode = await api.get_beatmap(beatmap_id=map_id)

            result = await pp(map_id, mods, mode.mode)

            for r in result.split("\n"):
                return r