Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import re
- import sys
- import time
- import praw
- import ctypes
- import random
- import win32ui
- import asyncio
- import discord
- import pyimgur
- import requests
- import subprocess
- from time import sleep
- from bs4 import BeautifulSoup
- from selenium import webdriver
- from datetime import datetime, time
- from praw.exceptions import ClientException
- # channels
- memes = ''
- megalinks = ''
- bots = ''
- channel_id = bots
- owner = ''
- client_id = ''
- # emoji control
- white_skin = ':skin-tone-1:'
- black_skin = ':skin-tone-5:'
- skin_tone = white_skin
- peace_emoji = ':v:' + skin_tone
- ok_emoji = ':ok_hand:' + skin_tone
- def WindowExists(classname):
- try:
- win32ui.FindWindow(None, classname)
- except win32ui.error:
- return False
- else:
- return True
- CACHE = {}
- # on start events
- print ("\nStatus: Connecting.")
- client = discord.Client()
- channel = discord.Object(id=channel_id)
- bot_token = ''
- bot_name = 'Bingo-Bot'
- slave_bot_name = 'Bungo-Bot'
- bot_version = '1.5.0'
- ctypes.windll.kernel32.SetConsoleTitleW(bot_name)
- # on message events
- @client.event
- async def on_message(message):
- if message.author == client.user:
- return
- if message.content.startswith('!view'):
- cmd = str(message.content).split()
- im = pyimgur.Imgur(client_id)
- scrape_url = cmd[1]
- if scrape_url.startswith('http'):
- scrape_url = scrape_url
- else:
- scrape_url = 'http://' + scrape_url
- fetching = 'Scraping %s. This takes a little while.' % (scrape_url)
- await client.send_message(client.get_channel(channel_id), fetching)
- filename = 'k.png'
- download_location = 'E:/screenshots/%s' % (filename)
- title = 'screenshot of %s' % (scrape_url)
- driver = webdriver.Firefox()
- driver.maximize_window()
- driver.set_window_position(2000, 2000)
- driver.get(scrape_url)
- driver.save_screenshot(download_location)
- driver.quit()
- saving = "Saving screenshot... We're halfway there."
- await client.send_message(client.get_channel(channel_id), saving)
- await client.purge_from(client.get_channel(channel_id), limit=100, check=lambda m: m.content == fetching)
- uploaded_image = im.upload_image(download_location, title=title)
- uploading = 'Uploading screenshot... Almost done.'
- await client.send_message(client.get_channel(channel_id), uploading)
- await client.purge_from(client.get_channel(channel_id), limit=100, check=lambda m: m.content == saving)
- img_url = uploaded_image.link
- msg = img_url
- await asyncio.sleep(2)
- await client.purge_from(client.get_channel(channel_id), limit=100, check=lambda m: m.content == uploading)
- await client.send_typing(client.get_channel(channel_id))
- await asyncio.sleep(.3)
- await client.send_message(client.get_channel(channel_id), msg)
- os.system("taskkill /im firefox.exe")
- if message.content.startswith('!reddit'):
- cmd = str(message.content).split()
- subreddit = cmd[2]
- try:
- post_limit = int(cmd[3])
- except IndexError:
- post_limit = 3
- reddit = praw.Reddit(
- client_id='',
- client_secret='',
- password='',
- user_agent='',
- username='')
- if cmd[1] == 'top':
- for submission in reddit.subreddit(subreddit).top(limit=post_limit):
- msg = submission.url
- await client.send_typing(client.get_channel(channel_id))
- await asyncio.sleep(.3)
- await client.send_message(client.get_channel(channel_id), msg)
- if cmd[1] == 'new':
- for submission in reddit.subreddit(subreddit).new(limit=post_limit):
- msg = submission.url
- await client.send_typing(client.get_channel(channel_id))
- await asyncio.sleep(.3)
- await client.send_message(client.get_channel(channel_id), msg)
- if cmd[1] == 'random':
- try:
- random_post = reddit.subreddit(subreddit).random()
- msg = random_post.url
- except ClientException as ce:
- if ce.args[0].lower().endswith(subreddit.lower() + '/'):
- msg_error = 'Reddit bug, getting random post client-side...'
- await client.send_typing(client.get_channel(channel_id))
- await asyncio.sleep(.3)
- await client.send_message(client.get_channel(channel_id), msg_error)
- sort = random.choice(('new', 'hot'))
- method = getattr(reddit.subreddit(subreddit), sort)
- now = time()
- last = CACHE[sub][sort + '_time']
- if CACHE[subreddit][sort] is None or last is None or (last + cache_time) < now:
- pool = CACHE[subreddit][sort] = tuple(method(limit=250))
- CACHE[subreddit][sort + '_time'] = now
- else:
- pool = CACHE[subreddit][sort]
- random_post = random.choice(pool)
- await client.purge_from(client.get_channel(channel_id), limit=100, check=lambda m: m.content == msg_error)
- msg = random_post.url
- await client.send_typing(client.get_channel(channel_id))
- await asyncio.sleep(.3)
- await client.send_message(client.get_channel(channel_id), msg)
- if message.content.startswith('!xbox'):
- gamertag = message.content.strip('!xbox ')
- gamertag_url = 'https://www.xboxgamertag.com/search/' + gamertag
- gamertag_url_request = requests.get(gamertag_url)
- soup = BeautifulSoup(gamertag_url_request.text, 'html.parser')
- if 'An error occured...' in gamertag_url_request.text:
- msg = 'That is not a valid Gamertag.'
- await client.send_typing(client.get_channel(channel_id))
- await asyncio.sleep(.3)
- await client.send_message(client.get_channel(channel_id), msg)
- if 'An error occured...' not in gamertag_url_request.text:
- status = soup.find('p', attrs={'class' : 'topc'}).get_text(strip=True)
- if ' playing Xbox Live' in status:
- status = status.replace(' playing Xbox Live', '')
- if 'Online now' in status:
- status = 'Online'
- if 'over 30 days ago' in status:
- status = 'Offline for over 1 month.'
- if 'Last seen' in status:
- status = 'Offline **//** ' + status[:-9]
- gamerscore = soup.findAll(attrs={"name":"description"})
- gamerscore = gamerscore[0]['content']
- gamerscore = re.sub("\D", "", gamerscore)
- gamerscore = format(int(gamerscore), ',d')
- msg = (
- "**%s's** Status: **%s**\n"
- "**%s's** Gamerscore: **%s**"
- ) % (
- gamertag.title(), status.title(), gamertag.title(), gamerscore
- )
- await client.send_typing(client.get_channel(channel_id))
- await asyncio.sleep(.3)
- await client.send_message(client.get_channel(channel_id), msg)
- if message.content.startswith('!countdown'):
- def dateDiffInSeconds(date1, date2):
- timedelta = date2 - date1
- return timedelta.days * 24 * 3600 + timedelta.seconds
- def daysHoursMinutesSecondsFromSeconds(seconds):
- minutes, seconds = divmod(seconds, 60)
- hours, minutes = divmod(minutes, 60)
- days, hours = divmod(hours, 24)
- return (days, hours, minutes, seconds)
- injustice2 = datetime.strptime('2017-05-15 23:01:00', '%Y-%m-%d %H:%M:%S')
- fridaythe13th = datetime.strptime('2017-05-25 23:01:00', '%Y-%m-%d %H:%M:%S')
- shadowofwar = datetime.strptime('2017-08-21 23:01:00', '%Y-%m-%d %H:%M:%S')
- now = datetime.now()
- msg = (
- '**%d** days, **%d** hours, **%d** minutes, and **%d** seconds until the release of **Injustice 2**.\n'
- '**%d** days, **%d** hours, **%d** minutes, and **%d** seconds until the release of **Friday the 13th: The Game**.\n'
- '**%d** days, **%d** hours, **%d** minutes, and **%d** seconds until the release of **Middle-earth: Shadow of War**.'
- ) % (
- daysHoursMinutesSecondsFromSeconds(dateDiffInSeconds(now, injustice2)) +
- daysHoursMinutesSecondsFromSeconds(dateDiffInSeconds(now, fridaythe13th)) +
- daysHoursMinutesSecondsFromSeconds(dateDiffInSeconds(now, shadowofwar))
- )
- await client.send_typing(client.get_channel(channel_id))
- await asyncio.sleep(.2)
- await client.send_message(client.get_channel(channel_id), msg)
- if message.content.startswith('!launch') and message.author.name == owner:
- process = message.content.strip('!launch ')
- msg = "Starting **%s**." % (process)
- print('%s: %s' %(message.author.name, message.content))
- print ('Status: Launching %s' % (process))
- await client.send_typing(client.get_channel(channel_id))
- await asyncio.sleep(.3)
- await client.send_message(client.get_channel(channel_id), msg)
- subprocess.Popen(process, creationflags=subprocess.CREATE_NEW_CONSOLE)
- if message.content.startswith('!purge') and message.author.name == owner:
- text_channel = message.content.strip('!purge ')
- if text_channel == 'memes':
- text_channel_id = memes
- if text_channel == 'megalinks':
- text_channel_id = megalinks
- if text_channel == 'bots':
- text_channel_id = bots
- await client.purge_from(client.get_channel(text_channel_id), limit=100, check=None)
- await client.send_typing(client.get_channel(channel_id))
- await asyncio.sleep(.3)
- if text_channel_id == memes:
- await client.send_message(client.get_channel(channel_id), 'Successfully purged **#memes**. %s' % (ok_emoji))
- print('%s: %s' %(message.author.name, message.content))
- print ('Status: Cleaned contents of #memes.')
- if text_channel_id == megalinks:
- await client.send_message(client.get_channel(channel_id), 'Successfully purged **#megalinks**. %s' % (ok_emoji))
- print('%s: %s' %(message.author.name, message.content))
- print ('Status: Cleaned contents of #megalinks.')
- if text_channel_id == bots:
- await client.send_message(client.get_channel(channel_id), 'Successfully purged **#bots**. %s' % (ok_emoji))
- print('%s: %s' %(message.author.name, message.content))
- print ('Status: Cleaned contents of #bots.')
- if message.content.startswith('!fix'):
- msg = "Restarting: **%s** and **%s**. %s" % (bot_name, slave_bot_name, peace_emoji)
- await client.purge_from(client.get_channel(channel_id), limit=100, check=lambda m: m.content == '!fix')
- await client.send_typing(client.get_channel(channel_id))
- await client.send_message(client.get_channel(channel_id), msg)
- print('%s: %s' %(message.author.name, message.content))
- print ('\nStatus: Restarting %s and %s.' %(bot_name, slave_bot_name))
- subprocess.Popen(bot_name + '.bat', creationflags=subprocess.CREATE_NEW_CONSOLE)
- subprocess.Popen(slave_bot_name + '.bat', creationflags=subprocess.CREATE_NEW_CONSOLE)
- else:
- if message.author.name != "null":
- if message.channel.id != bots or message.content.startswith('!') or message.content.startswith('http'):
- return
- if message.author.name == "Bango-Bot" or message.author.name == "Bingo-Bot" or message.author.name == "Bungo-Bot":
- return
- else:
- confusing_url = 'http://my.confusing.life/'
- confusing_url_request = requests.get(confusing_url)
- soup = BeautifulSoup(confusing_url_request.text, 'html.parser')
- confusing_quote = soup.find("span").get_text(strip=True)
- msg = confusing_quote
- await client.send_typing(client.get_channel(channel_id))
- await asyncio.sleep(.3)
- await client.send_message(client.get_channel(channel_id), msg)
- print('%s: %s' %(message.author.name, message.content))
- print('%s: %s' %(bot_name, msg))
- # on connect events
- @client.event
- async def on_ready():
- print ("Status: Connected!")
- print('------')
- print('Bot: ' + client.user.name)
- print('Client ID: ' + client.user.id)
- print('------')
- default_presence = 'Bingo-Bot v%s' % (bot_version)
- print ('Current presence: %s' %(default_presence))
- await client.change_presence(game=discord.Game(name=default_presence))
- await client.purge_from(client.get_channel(channel_id), limit=100, check=None)
- await client.send_typing(client.get_channel(channel_id))
- if WindowExists("Bungo-Bot"):
- msg = (
- '**%s** Status: **Online** %s\n'
- '**%s** Status: **Online** %s'
- ) % (
- bot_name, ok_emoji, slave_bot_name, ok_emoji
- )
- await client.send_message(client.get_channel(channel_id), msg)
- else:
- msg = (
- '**%s** Status: **Online** %s\n'
- '**%s** Status: **Offline** %s'
- ) % (
- bot_name, ok_emoji, slave_bot_name, peace_emoji
- )
- await client.send_message(client.get_channel(channel_id), msg)
- # sign in
- client.run(bot_token)
Add Comment
Please, Sign In to add comment