Skip to content

Commit

Permalink
Add command to get random xkcd
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Oct 6, 2022
1 parent 7b5f5f5 commit a498caf
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions xkcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,15 @@ async def search(self, evt: MessageEvent, query: str) -> None:
f"with a similarity lower than {similarity + 0.1} %")
await evt.reply(msg)

@xkcd.subcommand("random", help="Show a random XKCD")
async def random(self, evt: MessageEvent) -> None:
random_id = random.randint(1, self.latest_id)
xkcd = await self.get_xkcd(random_id)
if not xkcd:
await evt.reply(f"Chose {random_id}, but failed to fetch content")
return
await self.send_xkcd(evt.room_id, xkcd)

@xkcd.subcommand("subscribe", help="Subscribe to xkcd updates")
async def subscribe(self, evt: MessageEvent) -> None:
sub = self.subscriber.query.get(evt.room_id)
Expand Down

0 comments on commit a498caf

Please sign in to comment.