-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
62 lines (46 loc) · 2.09 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
Created By Jivansh Sharma
April 2022
@parzuko
"""
from get_token import token as TOKEN
from models import MetroGraph
import discord
kamui = discord.Bot()
kamui_url = "https://github.com/parzuko/kamui/blob/main/assets/kamui.jpeg?raw=true"
kamui_graph = MetroGraph()
kamui_graph.populate_graph()
def style_shortest_path(shortest_path):
styled_shortest_path = []
for station in shortest_path:
pretty_station = f"{station.capitalize()} {kamui_graph.get_station_line(station)}"
styled_shortest_path.append(pretty_station)
return styled_shortest_path
class MyModal(discord.ui.Modal):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.add_item(discord.ui.InputText(label="Start Point"))
self.add_item(discord.ui.InputText(label="Destination"))
async def callback(self, interaction: discord.Interaction):
source = self.children[0].value.lower()
destination = self.children[1].value.lower()
embed = discord.Embed(
title="Mangekyou Sharingan!",
description=f"We got the shortest path from {source.capitalize()} to {destination.capitalize()}",
color=discord.Colour.random(),
)
shortest_path, duration = kamui_graph.get_shortest_path(source, destination)
styled_shortest_path = style_shortest_path(shortest_path)
embed.set_author(name="Kamui", icon_url=kamui_url)
embed.add_field(name="Shortest Path", value=(" → ").join(styled_shortest_path))
embed.set_footer(text=f"This route will take {int(duration)} minutes!")
await interaction.response.send_message(embeds=[embed])
@kamui.event
async def on_ready():
print(f"{kamui.user} is ready and online!")
@kamui.slash_command(name="kamui", description="Find the shortest path between two metro stations!")
async def modal_slash(ctx: discord.ApplicationContext):
"""Shows an example of a modal dialog being invoked from a slash command."""
modal = MyModal(title="Calculate Shortest Path!")
await ctx.send_modal(modal)
kamui.run(TOKEN)