#view in dm doesn't work

1 messages · Page 1 of 1 (latest)

distant solar
#

I am sending a view in dm but it doesn't work, selecting an option does nothing and the print isn't reached

@plugin.command
@lightbulb.command('newraid', 'Create a new raid')
@lightbulb.implements(lightbulb.SlashCommand)
async def NewRaid(ctx):
    await ctx.respond('I sent you a direct message, please follow the instructions there to create your raid!')
    channel = await plugin.bot.rest.create_dm_channel(ctx.member.id)
    view = RaidSelectView(timeout=60)
    await channel.send("", components=view)

class RaidSelectView(miru.View):
    @miru.text_select(
        placeholder="Choose the raid",
        options= [
            miru.SelectOption(label="Valehir"),
            miru.SelectOption(label="Alzanor")
        ]
    )
    async def RaidSelect(self, select: miru.TextSelect, ctx: miru.ViewContext) -> None:
        print(select.values[0])
        channel = await plugin.bot.rest.create_dm_channel(ctx.member.id)
        await channel.send(f"You've chosen {select.values[0]}!")
willow marsh
#

in the server you share with the bot, do you have allow dms enabled?

#

@distant solar

distant solar
#

yes, I receive the dms but selecting the option does nothing

wheat needle
#

Any error @distant solar ?

#

Oh

#

You never start the view @distant solar

distant solar
#

oh yeah that would explain it

willow marsh
#

are you handling these views?

#

oops those messages did not come through till very late

distant solar
#

I ended up not doing it by dm

#

so far I got view + modal chained together to get data

#

edited init of both to pass a raid variable

#

end up with a forum post containing an embed and I add reactions on it

#

next step would be doing stuff when someone reacts on it

#

looks like this

#
@plugin.command
@lightbulb.command('newraid', 'Create a new raid')
@lightbulb.implements(lightbulb.SlashCommand)
async def NewRaid(ctx):
    # await ctx.respond('I sent you a direct message, please follow the instructions there to create your raid!')
    # channel = await plugin.bot.rest.create_dm_channel(ctx.member.id)
    raid = Raid()
    raid.datetime = dt.datetime.now(tz=datetime.timezone.utc)
    raid.host = ctx.member.display_name
    ActiveRaids.append(raid)
    view = RaidSelectView(raid=raid)
    # await channel.send("", components=view)
    message = await ctx.respond("", components=view)
    await view.start(message)

class RaidSelectView(miru.View):
    def __init__(self, *, timeout: float | int | None = 120, autodefer: bool = True, raid: Raid) -> None:
        super().__init__(timeout=timeout, autodefer=autodefer)
        self.raid = raid
    @miru.text_select(
        placeholder="Choose the raid",
        options= [
            miru.SelectOption(label="Valehir"),
            miru.SelectOption(label="Alzanor")
        ]
    )
    async def RaidSelect(self, select: miru.TextSelect, ctx: miru.ViewContext) -> None:
        self.raid.name = select.values[0]
        # await ctx.respond(f"You've chosen {select.values[0]}!")
        x = self.raid
        modal = RaidSelectInfoModal(title="Raid information", raid=x)
        await ctx.respond_with_modal(modal)
#
class RaidSelectInfoModal(miru.Modal):
    def __init__(self, title: str, *, custom_id: str | None = None, timeout: float | int | None = 300, raid: Raid) -> None:
        super().__init__(title, custom_id=custom_id, timeout=timeout)
        self.raid = raid
    time = miru.TextInput(label="Start time (server time)", value="hh:mm", required=True)
    size = miru.TextInput(label="Team size", placeholder="8, 15 or 20", required=True)
    ddmax = miru.TextInput(label="Total DDs", placeholder="How many damage dealers do you want? Numbers only", required=True)
    suppmax = miru.TextInput(label="Total supps", placeholder="How many supports do you want? Numbers only", required=True)
    description = miru.TextInput(label="Description", placeholder="Anything you want mention in your post", style=hikari.TextInputStyle.PARAGRAPH, value="")

    async def callback(self, ctx: miru.ModalContext) -> None:
        self.raid.time = self.time.value
        self.raid.size = self.size.value
        self.raid.ddmax = self.ddmax.value
        self.raid.suppmax = self.suppmax.value
        self.raid.description = self.description.value
        embed = (
            hikari.Embed(
            title = self.raid.time+" "+self.raid.name+" by "+self.raid.host,
            description = self.raid.description,
            timestamp=self.raid.datetime
            )
            .add_field(name="Team count", value=f"{self.raid.ddcount + self.raid.suppcount}/{self.raid.size}")
            .add_field(name="DD count", value=f"{self.raid.ddcount}/{self.raid.ddmax} :crossed_swords:")
            .add_field(name="Supp count", value=f"{self.raid.suppcount}/{self.raid.suppmax} :shield:")
        )
#
await ctx.respond('Done!')
newraid = await plugin.bot.rest.create_forum_post(1123295897682444328, embed.title, embed=embed, content='<@&1118541103243731005>', role_mentions=True)
await plugin.bot.rest.add_reaction(channel=newraid.id, message=newraid.id, emoji="⚔")
await plugin.bot.rest.add_reaction(channel=newraid.id, message=newraid.id, emoji=":shield:")
#

@willow marsh

#
ActiveRaids = []

class Raid:
    datetime = None
    name = ""
    time = ""
    host = ""
    description = ""
    size = 0
    ddcount = 0
    ddmax = 0
    suppcount = 0
    suppmax = 0
willow marsh
#

yep that seems fine whats up

distant solar
#

just wanted to share the progress

willow marsh
#

ah

distant solar
#

if you could point me to how I can start a listener for reaction on a post that would be great tho

#

I was thinking perpetual listener and check ActiveRaids[] but maybe theres better

willow marsh
#

well the easiest way is to store that document somewhere, and then use hikari.ReactionAddEvent

distant solar
#

can I create a local json file or something

willow marsh
#

jsons are not a good idea to storing data

#

I would suggest using a database

distant solar
#

is there a doc for that

willow marsh
#

well depends what type of database you want to use

distant solar
#

easiest to implement and work with?

willow marsh
#

there are local ones (files) or server ones

#

files

#

imo at least, unless you already have a server one running

distant solar
#

I have a server

willow marsh
#

well you could set up a server one if you wanted to. It really boils down to personal preference.
The server is good if you plan to have a few databases in different places, or multiple programs accessing the same database
The local file option is better for basic applications, where you only need that one program to access.
Servers can be a little more challenging to set up, because you cant just make a file and call it done, but they would be a great start, and there are ways to transfer the database in the future if need be

distant solar
#

local file probably better for me to get started

willow marsh
#

thats fair

#

the library I use is called aiofiles

distant solar
#

I also want to create templates for raids with those local files

#

ok ty I'll look at it

willow marsh
#

let me know if you need any more help with it!

distant solar
#

sure thing, appreciate your help through this