Guest User

Cheesecake Bot v1.2

a guest
Feb 19th, 2022
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.73 KB | None | 0 0
  1. import discord
  2. import os
  3. import requests
  4. from datetime import date, timedelta
  5. import re
  6. # link: https://discord.com/api/oauth2/authorize?client_id=943981035950051328&permissions=534723947584&scope=bot
  7.  
  8. client = discord.Client()
  9.  
  10. def search():
  11.     full_menu = ""
  12.     day = date.today()
  13.     delta = timedelta(days=1)
  14.     cheesecake_dates = []
  15.     today = False
  16.     for i in range(7):
  17.         d_str = day.strftime("%m/%d/%y")
  18.         full_menu += d_str+"\n"
  19.         day += delta
  20.         query = {'tid':'1', 'date':d_str}
  21.         response = requests.get("https://umassdining.com/foodpro-menu-ajax", params=query)
  22.         j = response.json()
  23.         for key in j.keys():
  24.             meal = j[key]
  25.             if 'Desserts' in meal.keys():
  26.                 d = meal['Desserts']
  27.                 r = re.findall('data-dish-name=\"([^\"]*)\"', d)
  28.                 for dessert in r:
  29.                     if dessert.lower().find('cheesecake') > -1:
  30.                         if i == 0:
  31.                             today = True
  32.                         elif len(cheesecake_dates) == 0 or cheesecake_dates[len(cheesecake_dates)-1] != day.strftime('%A'):  
  33.                             cheesecake_dates.append(day.strftime('%A'))
  34.                 full_menu += key.capitalize() + ': ' + ', '.join(r) + "\n"
  35.     to_return = ''
  36.     if(today):
  37.         to_return += "There is cheescake today! :)\n"
  38.         if len(cheesecake_dates) == 1:
  39.             to_return +="There is also cheesecake on "+cheesecake_dates[0]+"!\n"
  40.         elif len(cheesecake_dates) > 1:
  41.             to_return +="There is also cheesecake on "+cheesecake_dates[0]+" and "+cheesecake_dates[1]+"!\n"
  42.     elif len(cheesecake_dates) == 1:
  43.         to_return +="There is no cheesecake today :(, but there is cheesecake on "+cheesecake_dates[0]+"!\n"
  44.     elif len(cheesecake_dates) > 1:
  45.         to_return +="There is no cheesecake today :(, but there is cheesecake on "+cheesecake_dates[0]+" and "+cheesecake_dates[1]+"!\n"
  46.     else:
  47.         to_return += "There is no cheesecake this week :(\n"
  48.     to_return += "\nHere's the full menu:\n"
  49.     to_return += '```\n'
  50.     to_return += full_menu
  51.     to_return += '\n```'
  52.     return to_return
  53.  
  54. @client.event
  55. async def on_ready():
  56.     print("Loaded")
  57.  
  58. @client.event
  59. async def on_message(message):
  60.     if message.author == client.user:
  61.         return
  62.     content = message.clean_content.lower()
  63.     if content.find('cheesecakebot') > -1 or content.find('cheescakebot') > -1 or content.find('dessert') > -1 or content.find('menu') > -1:
  64.         await message.channel.send(search())
  65.  
  66.     elif len(re.findall("c[\W]*h[\W]*e[\W]*e[\W]*s[\W]*e?[\W]*c[\W]*a[\W]*k[\W]*e", content)) > 0:
  67.         await message.channel.send('Cheesecake!')
  68.  
  69. client.run(TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment