Esempio n. 1
0
async def on_message_delete(pid, client, message):
    import message_transfer
    import copy

    opted_user = core.read_memory(pid, "user")
    target_channel = core.read_memory(pid, "channel")

    messages = read_messages(pid)

    if message.author == opted_user and isinstance(message.channel, discord.DMChannel):
        corresponding_messages = [ m for m in messages if m.source_message == message ]
        for m in corresponding_messages:
            await m.delivered_message.delete()
    elif message.channel == target_channel and message.author != client.user:
        corresponding_messages = [ m for m in messages if m.source_message == message ]
        for m in corresponding_messages:
            embed = create_deleted_message_embed(message)
            await m.delivered_message.edit(embed = embed)
    else:
        return

    for c_message in corresponding_messages:
        messages.remove(c_message)

    core.write_memory(pid, "messages", messages)
Esempio n. 2
0
async def on_process_start(pid, user, channel):
    core.write_memory(pid, "user", user)
    core.write_memory(pid, "channel", channel)

    users = core.read_global_memory(puid, "users")
    if not users:
        users = []

    for u, p in users:
        if u == user:
            await core.end_process(p)
            users.remove((u, p))

    users.append((user, pid))
    core.write_global_memory(puid, "users", users)

    await user.send("Successfully opted in!")
Esempio n. 3
0
async def on_message_edit(pid, client, before, after):
    import message_transfer

    opted_user = core.read_memory(pid, "user")
    target_channel = core.read_memory(pid, "channel")

    messages = read_messages(pid)

    if before.author == opted_user and isinstance(before.channel, discord.DMChannel): # opted user edited their own message
        corresponding_messages = [ message for message in messages if message.source_message == before ]
        for m in corresponding_messages:
            await m.delivered_message.edit(content = message_transfer.process_message(after.content, target_channel, client))

    elif before.channel == target_channel and before.author != client.user: # a message was edited in the opted channel
        corresponding_messages = [ message for message in messages if message.source_message == before ]
        for m in corresponding_messages:
            await m.delivered_message.edit(embed = create_message_embed(after))
    else:
        return

    core.write_memory(pid, "messages", messages)
Esempio n. 4
0
async def on_message(pid, client, message):
    import message_transfer
    opted_user = core.read_memory(pid, "user")
    target_channel = core.read_memory(pid, "channel")

    messages = read_messages(pid)

    if message.author == opted_user and isinstance(message.channel, discord.DMChannel):
        if message.content.strip() == "bundes transfer opt-out":
            await message.channel.send("Opting out...")
            await core.end_process(pid)
            return

        files = None
        if len(message.attachments) > 0:
            files = [ await f.to_file() for f in message.attachments ]

        reference = find_message_corresponding_reference(await find_message_original_reference(message, client), messages)
        sent_message = await target_channel.send(content = message_transfer.process_message(message.content, target_channel, client),
                                                 files = files,
                                                 reference = reference)

    elif message.channel == target_channel and message.author != client.user:
        files = None
        if len(message.attachments) > 0:
            files = [ await f.to_file() for f in message.attachments ]

        reference = find_message_corresponding_reference(await find_message_original_reference(message, client), messages)
        sent_message = await opted_user.send(files = files, embed = create_message_embed(message), reference = reference)

    else:
        return
    
    messages = [ *messages[ max(0, len(messages) - MAX_SAVED_MESSAGES + 1) : ],
                 Message(source_message = message, delivered_message = sent_message) ] 

    core.write_memory(pid, "messages", messages)
Esempio n. 5
0
async def process(pid, message, client):
    game = core.read_memory(pid, "game")
    if not game:
        game = Game("not started", [])
        core.write_memory(pid, "game", game)

    if message.content.startswith("bundes indian"):
        params = message.content.split(" ")[2:]
        if len(params) > 0 and params[0] == "start":
            if game.state != "not started":
                await message.channel.send(
                    "No, no, no. Only one game at a time. I'm sorry.")
                await message.channel.send(
                    "There's already another game going on or waiting for players. Try again next time."
                )
                return

            g1 = replace(game, state="waiting")
            g2 = register_player(g1, message.author)
            core.write_memory(PID, "game", g2)

            await message.channel.send("Let's freaking go!")
            await message.channel.send(
                "Type `bundes indian join` to join the game!")