Last active 1722994751

uses https://github.com/alyssadev/python-discord-bot

bot.py Raw
1#!/usr/bin/env python3
2from requests import get
3from interactions import slash_command, SlashContext, Client, slash_option, OptionType, auto_defer, Embed, check, AutocompleteContext, listen
4from os import environ
5
6suburbs = {f"{d['locality']} {d['state']}": d for d in get("https://www.matthewproctor.com/Content/postcodes/australian_postcodes.json").json()}
7
8bot = Client(token=environ["BOT_TOKEN"])
9guilds = [353071720342487040]
10
11@slash_command(name="fuel", description="Check Fair Fuel prices (RACQ)", scopes=guilds)
12@slash_option(name="location", description="Suburb", required=True, opt_type=OptionType.STRING, autocomplete=True)
13async def fuel(ctx: SlashContext, location: str):
14 suburb = suburbs[location]
15 fair_response = get("https://www.racq.com.au/ajaxpages/fuelprice/fairfuelpricesapi.ashx", params={"lat": suburb["lat"], "lng": suburb["long"], "fueltype": 37}).json()
16# area_response = get(f"https://www.racq.com.au/ajaxpages/fuelprice/fuelpricesapi.ashx?lat={suburb['lat']}&lng={suburb['long']}&fueltype=37").json()
17 embed = Embed(title="Area prices").add_field(name="RACQ", value=f"https://www.racq.com.au/car/fair-fuel-prices?phracq_body_0_phracq_contentcontainer_0_FuelTypesDDL=37&location={location.replace(' ', '%20')}").add_field(name="PetrolSpy", value=f"https://petrolspy.com.au/map/latlng/{suburb['lat']}/{suburb['long']}")
18# for station in area_response["Stations"]:
19# embed.add_field(name=station["Name"], value=station["Price"])
20 await ctx.send(f"Fair Fuel price in {fair_response['FairPrice']['Location']}: {fair_response['FairPrice']['RoundedPrice']}{' :thumbsup:' if fair_response['FairPrice']['PriceIndicator'] == 2 else ''}", embed=embed)
21
22@fuel.autocomplete("location")
23async def autocomplete(ctx: AutocompleteContext):
24 inp = ctx.input_text.lower()
25 results = [a for a in suburbs if a.lower().startswith(inp)][:25]
26 await ctx.send(choices=[{"name": r, "value": r} for r in results])
27
28@listen()
29async def on_startup():
30 print("Bot started")
31
32bot.start()
docker-compose.yml Raw
1services:
2 bot:
3 image: ghcr.io/alyssadev/python-discord-bot:latest
4 environment:
5 - BOT_TOKEN=-
6 volumes:
7 - .:/usr/src/app
8 - /etc/localtime:/etc/localtime:ro
9 restart: always