Created
March 30, 2018 00:33
-
-
Save DrMkdaddy/ae5bfd17d942c6b8ea3a824fda46b809 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 import Client | |
from yaml import safe_load | |
import asyncio | |
from pathlib import Path | |
from hashlib import sha224 | |
import requests | |
from base64 import b64decode | |
class CheckSite(Client): | |
def __init__(self): | |
super().__init__() | |
self.create_config() | |
self.template = b'U2l0ZXM6DQogIC0gI0xpc3Qgb2YgYWxsIHlvdXIgc2l0ZXMgKHBlciBwYWdlKQ0KDQpUb2tlbjogIyBZb3VyIEJvdCBUb2tlbg0KDQpUaW1lOiAjIFNldCB0aGUgdGltZSBiZXR3ZWVuIHNjYW5zIGluIG1pbnV0ZXMNCg0KTWVzc2FnZV9DaGFubmVsOg0KICAtICMgQ2hhbm5lbHMgd2hlcmUgdGhlIGJvdCB3aWxsIHNlbmQgbWVzc2FnZXMgKE1VU1QgQkUgSURzIGFuZCBpbiBzZXJ2ZXJzIHdoZXJlIHRoZSBib3QgaXMpDQo=' | |
self.site_list = self.config.get('Sites') | |
self.time_to_take = self.config.get('Time') * 60 or 30 * 60 | |
self.token = self.config.get('Token') | |
self.bg_task = self.loop.create_task(self.checksites()) | |
def create_config(self): | |
config_file = Path(f'config.yml') | |
if not config_file.exists(): | |
print("There is now a config.yml file, please place in your configuration details and restart the bot") | |
with open('config.yml', 'wb') as f: | |
f.write(b64decode(self.template)) | |
self.config = safe_load("config.yml") | |
async def checksites(self): | |
await self.wait_until_ready() | |
for site in self.site_list: | |
resp = requests.get(self.site_list[site]) | |
site_hash = {} | |
site_hash_og = {} | |
site_hash_og[self.site_list.get(site)] = sha224(resp.text()).hexdigest() | |
resp_new = requests.get(self.site_list[site]) | |
if site_hash[self.site_list.get(site)] != sha224(resp_new.text()).hexdigest(): | |
print(f"{self.site_list[site]} has updated!") | |
await client.send_message(f'The site {self.site_list[site]} has updated!', self.config.get('Message_Channel')) | |
await asyncio.sleep(self.time_to_take) | |
async def on_ready(self): | |
print(f"Time between scans is {self.time_to_take / 60} minutes long") | |
print('READY!') | |
print(f'Loaded {len(self.site_list)}') | |
print(f'Signed in as {self.user.name}') | |
print(f'Inv Link: https://discordapp.com/oauth2/authorize?client_id={client.user.id}&scope=bot') | |
if __name__ == '__main__': | |
cs = CheckSite() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment