Advertisement
Y0Landi

Untitled

Apr 19th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.96 KB | None | 0 0
  1. import discord
  2. import asyncio
  3. import random
  4. from discord.ext.commands import Bot
  5. from discord.ext import commands
  6. from datetime import *
  7. from threading import Timer
  8. from time import *
  9. import sched,time
  10. from textwrap import *
  11. import pickle
  12. global month,day,birthdays
  13. month = datetime.now().month## for testing change .month to .minute
  14. day = datetime.now().day## for testing change .day to .second
  15. global birthdays
  16. bdaylink = ['https://media.giphy.com/media/3ohhwmQ0xIg8W3pHd6/giphy.gif',
  17.             'https://media.giphy.com/media/IQF90tVlBIByw/giphy.gif',
  18.             'https://media.giphy.com/media/xT0BKqhdlKCxCNsVTq/giphy.gif',
  19.             'https://media.giphy.com/media/26FPIV12CYbDSVIR2/giphy.gif',
  20.             'https://media.giphy.com/media/yoJC2GnSClbPOkV0eA/giphy.gif',
  21.             'https://media.giphy.com/media/YTbZzCkRQCEJa/giphy.gif',
  22.             'https://media.giphy.com/media/3oEhn78T277GKAq6Gc/giphy.gif',
  23.             'https://media.giphy.com/media/kJLOin5OUi6uQ/giphy.gif',
  24.             'https://media.giphy.com/media/3ohzdHb9vMEkpuEy40/giphy.gif',
  25.             'https://media.giphy.com/media/xAFPuHVjmsBmU/giphy.gif',
  26.             'https://media.giphy.com/media/3o7btM5SfPJ8YlfjfW/giphy.gif',
  27.             'https://media.giphy.com/media/GXnaqmGcg1CTu/giphy.gif']
  28. bdaymessage = ['Celebrate your birthday today. Celebrate being Happy every day.',
  29.                'So many candles for such a small cake? Happy Birthday.',
  30.                'Wishing you a day that is as special in every way as you are. Happy Birthday.',
  31.                'Your birthday should be a national holiday. I need a day off. Happy Birthday.',
  32.                'You are a gift to the world. How is that for a reverse birthday wish. Happy Birthday.',
  33.                "It is your birthday so I'll make the toasts and you make the boasts. Happy Birthday."]
  34.  
  35. try:
  36.     pickle_in = open('birthdays.pickle','rb')
  37.     birthdays = pickle.load(pickle_in)
  38.     pickle_in.close()
  39. except:
  40.     birthdays = {}
  41.     birthdays['nonexist'] = '3213'
  42.     pickle_out = open('birthdays.pickle','wb')
  43.     pickle.dump(birthdays, pickle_out)
  44.     pickle_out.close()
  45. Client = discord.Client()
  46. bot_prefix = '.'
  47. client = commands.Bot(command_prefix = bot_prefix)
  48.  
  49. @bot.event
  50. async def on_ready():
  51.     global month,day
  52.     print('Bot Online!')
  53.     print('Name: {}'.format(bot.user.name))
  54.     print('ID: {}'.format(bot.user.id))
  55.     print(birthdays)
  56.  
  57.     while True:
  58.         if day != datetime.now().day:## for testing change .day to .second
  59.             for i in birthdays:
  60.                 userdate = wrap(birthdays[i],2)
  61.                 if int(userdate[0]) == month:
  62.                     if int(userdate[1]) == day:
  63.                         bdayboxtitle = random.choice(bdaymessage)
  64.                         bdaygifurl = random.choice(bdaylink)
  65.                         embed=discord.Embed(title=bdayboxtitle).set_image(url=bdaygifurl)
  66.                         await bot.send_message(i,embed=embed)
  67.  
  68.         month = datetime.now().month ## for testing change .month to .minute
  69.         day = datetime.now().day ## for testing change .day to .second
  70.         await asyncio.sleep(3600) ## for testing change 3600 to 1
  71.            
  72. @bot.command(pass_context=True)
  73. async def birthday(ctx, userdefinedbirthday, userid: discord.User):
  74.     try:
  75.         userbday = wrap(userdefinedbirthday,2)
  76.         usermonth = int(userbday[1])
  77.         if len(str(usermonth)) != 2:
  78.             usermonth = '0' + str(usermonth)
  79.         userday = int(userbday[0])
  80.         if len(str(userday)) != 2:
  81.             userday = '0' + str(userday)
  82.         birthdays[userid] = str(userday)+str(usermonth)
  83.         await bot.say('Birthday of '+str(userid)+'set to '+str(userday)+str(usermonth))
  84.         print(birthdays)
  85.         pickle_out = open('birthdays.pickle','wb')
  86.         pickle.dump(birthdays, pickle_out)
  87.         pickle_out.close()
  88.     except:
  89.         await bot.say('Invalid birthday format, please use `2402` for 24th of February')
  90.  
  91.  
  92. bot.run('<id>')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement