Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Add juice command #81

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion vyxalbot2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from vyxalbot2.commands import COMMAND_REGEXES, MESSAGE_REGEXES, COMMAND_ALIASES

__version__ = "2.0.0"
sale = [] # For juice command


class VyxalBot2(Application):
Expand Down Expand Up @@ -573,7 +574,23 @@ async def runCommand(
signal.raise_signal(signal.SIGINT)
else:
await self.room.reply(event.message_id, "Failed to pull!")

case "juice":
try:
global sale
if args["state"] == "sell":
sale.append({"price":args["price"],"juice":args["juice"]})
await self.room.reply(event.message_id, "Sold {0} juice for {1}.".format(args["juice"],args["price"]))
elif args["state"] == "browse":
prettified = '\n'.join("Juice number {0} is {1} juice and costs {2}.".format(sale.index(y),y["juice"],y["price"]) for y in sale)
await self.room.reply(event.message_id,"Here is the catalog of juices on sale:\n\n"+prettified)
elif args["state"] == "buy":
juicebuy = sale[int(args["number"])]
del sale[int(args["number"])]
await self.room.reply(event.message_id, "Bought juice number {0} ({1} juice) for {2}.".format(args["number"],juicebuy["juice"],juicebuy["price"]))
else:
await self.room.reply(event.message_id, "Hmm, this juicy transaction document appears to be illegible...")
except:
await self.room.reply(event.message_id, "Hmm, this juicy transaction document appears to be illegible...")

async def onMessage(self, room: Room, event: MessageEvent):
try:
Expand Down
1 change: 1 addition & 0 deletions vyxalbot2/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
r"idiom (?P<action>add) <b>(?P<title>.+)<\/b> <code>(?P<code>.+)<\/code> \"(?P<description>.+)\" (?P<keywords>[a-zA-Z0-9-?!*+=&%>< ]+)",
r"idiom (?P<action>search) (?P<keywords>[a-zA-Z0-9-?!*+=&%>< ]+)",
): "idiom",
(r"juice (?P<state>sell) (?P<juice>.+) (?P<price>\d+)",r"juice (?P<state>browse)",r"juice (?P<state>buy) (?P<number>\d+)"): "juice",
}
MESSAGE_REGEXES_IN: dict[tuple[str, ...], str] = {
(r"(wh?at( i[sz]|'s)? vyxal\??)", r"what vyxal i[sz]\??"): "info",
Expand Down