Skip to content

Instantly share code, notes, and snippets.

@sonic2kk
Last active September 16, 2022 04:50
Show Gist options
  • Save sonic2kk/1be43daaac9dd8a21082784f6e9f7305 to your computer and use it in GitHub Desktop.
Save sonic2kk/1be43daaac9dd8a21082784f6e9f7305 to your computer and use it in GitHub Desktop.
Play Trivia with the Discord bot Mantaro to your hearts content. Will not work on Wayland with versions of Pynput which do not support it.
import time
import random
from pynput.keyboard import Key, Controller
keyboard = Controller()
def press(key):
keyboard.press(key)
keyboard.release(key)
def type_phrase(phrase, enter=True):
phrase = str(phrase)
for char in phrase:
press(char)
if enter:
press(Key.enter)
def play_trivia():
type_phrase('->trivia', enter=True)
guess1 = random.randint(1, 4)
guess2 = random.randint(1, 4)
while guess1 == guess2:
guess2 = random.randint(1, 4)
time.sleep(1)
type_phrase(str(guess1))
press(Key.enter)
time.sleep(1)
type_phrase(str(guess2))
press(Key.enter)
time.sleep(7)
while True:
play_trivia()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment