You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.1 KiB
82 lines
2.1 KiB
#! /usr/bin/env python3
|
|
"""
|
|
Code for schneiderbot
|
|
"""
|
|
import os
|
|
import datetime
|
|
import urllib.request
|
|
import json
|
|
import logging
|
|
|
|
import discord
|
|
from discord.ext import commands
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
DESCRIPTION = '''Schneiderbot, bald mit tollen Funktionen'''
|
|
BOT = commands.Bot(command_prefix='!', description=DESCRIPTION)
|
|
MENSA_URL = {
|
|
"zentral": "zentralmensa",
|
|
"nord": "nordmensa",
|
|
"turm": "turmmensa"
|
|
}
|
|
MENSA_NAME = {
|
|
"zentral": "Zentralmensa",
|
|
"nord": "Nordmensa",
|
|
"turm": "Turmmensa"
|
|
}
|
|
|
|
@BOT.event
|
|
async def on_ready():
|
|
""" On ready """
|
|
print('Logged in as')
|
|
print(BOT.user.name)
|
|
print(BOT.user.id)
|
|
print('------')
|
|
|
|
@BOT.command()
|
|
async def hello():
|
|
"""Was ist das hier für eins Bot?"""
|
|
await BOT.say("""Hallo, ich bin ein Bot.
|
|
Ich liefere tolle Informationen über die Mensa. Die Infos kommen von
|
|
https://mensa.schneider-hosting.de
|
|
Mhmm, lecker. Guten Appetit!""")
|
|
|
|
@BOT.command()
|
|
async def mensa(which="zentral"):
|
|
"""Gibt leckere, äh, nützliche Infos über die Mensa aus.
|
|
Standardmäßig für die Zentralmensa, aber probier auch mal nord oder turm aus."""
|
|
|
|
today = datetime.datetime.now().date().weekday() + 1
|
|
if datetime.datetime.now().time() > datetime.time(hour=16):
|
|
# Es ist zu spät am Tag, zeig das essen für morgen an
|
|
today += 1
|
|
|
|
with urllib.request.urlopen("https://mensa.schneider-hosting.de/static/%s.%d.json" % (MENSA_URL[which], today)) as url:
|
|
data = json.loads(url.read().decode())
|
|
|
|
message = ""
|
|
for meal in data["meals"]:
|
|
meal_line = "**%s**\n" % meal["category"]
|
|
meal_line += meal["title"].strip() + "\n"
|
|
|
|
# Discord only allows up to 2000 chars per message
|
|
if len(message) + len(meal_line) > 2000:
|
|
await BOT.say(message)
|
|
message = meal_line
|
|
else:
|
|
message += meal_line
|
|
|
|
await BOT.say(message)
|
|
|
|
@BOT.command()
|
|
async def magie():
|
|
"""MAGIEEEEEE"""
|
|
await BOT.say("Magie ist Physik durch wollen!")
|
|
|
|
def main():
|
|
""" entry point """
|
|
BOT.run(os.environ['SCHNEIDERBOT_TOKEN'])
|
|
|
|
if __name__ == '__main__':
|
|
main()
|