Created
July 14, 2019 11:37
-
-
Save marios8543/a1e35ae780e33a122648d455f81439cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Discord.discord import Client | |
from thermal_printer import ThermalPrinter | |
from machine import UART | |
from uio import BytesIO | |
import btree | |
uart = UART(2,19200) | |
uart.init(19200, bits=8, parity=None, stop=1) | |
printer = ThermalPrinter(uart,auto_warm_up=False) | |
db = btree.open(BytesIO()) | |
cl = Client() | |
db['listen_channel'] = "" | |
def listen(msg): | |
db['listen_channel'] = msg.channel_id | |
printer.print("!Selecting channel {}".format(msg.channel_id)) | |
#cl.send(msg.channel_id,"Printing the messages from this channel") | |
cl.add_command(listen) | |
def on_message(msg): | |
if msg.channel_id == db['listen_channel'].decode("utf-8"): | |
print("Printing message") | |
printer.print("<{}> {}".format(msg.author.name,msg.content)) | |
cl.on_message_event(on_message) | |
printer.print("Starting discord printer...") | |
cl.start("TOKEN GOES HERE") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment