Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import sys
- import discord
- import asyncio
- import getpass
- import requests
- import time
- import re
- from bs4 import BeautifulSoup
- import pprint
- import json
- import signal
- client = discord.Client()
- master = "188846528553549824" #aiglebleu
- server_id = "181163144163491840" #hightechlowlife.eu
- channel_id = "181163144163491840" #htll
- url_login = "https://hightechlowlife.eu/board/login/login"
- url_shouty = "https://hightechlowlife.eu/board/index.php?chat/refresh"
- headers = { 'User-Agent' : "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36" }
- # Thanks to https://github.com/htll/Charitum/blob/master/charitum.py
- def callback_shutdown( signal, frame ):
- import sys
- print( "\nShutting down...\n" )
- sys.exit(0)
- # Thanks to https://github.com/SteveMcGrath/pyxenforo/blob/master/xenforo.py
- def getToken(page):
- token_rex = re.compile(r'\<a href\=\"logout/\?_xfToken\=(.+?[^\"])\"')
- token = token_rex.findall(page)[0]
- token = token.replace('%2C',',')
- return token
- # updates the session element with session cookies
- def login():
- # Prompt user for login and pass
- username = input("Username: ")
- password = getpass.getpass("Password: ")
- payload = { 'login' : username, 'password' : password, 'remember' : '1', 'register' : 0 }
- s.post(url_login, data=payload, headers=headers)
- return username
- # Returns a soup object of the html in the shoutbox
- def seekShouty(lastID):
- payload = {'_xfResponseType' : 'json', '_xfToken' : token, 'last_id' : lastID}
- r = s.post(url_shouty, headers=headers, data=payload)
- t = json.loads(r.text)
- return BeautifulSoup(t["messages"], "lxml")
- # Prints the shouty to console
- async def showShouty():
- await client.wait_until_ready()
- lastID = 0
- channel = discord.Object(id=channel_id)
- while not client.is_closed:
- soup = seekShouty(lastID)
- users = []
- for i in soup.findAll('li'):
- if i.has_attr('data-author'):
- users.append(i['data-author'])
- if int(i['id']) > lastID:
- lastID = int(i['id'])
- messages = []
- for i in soup.findAll('span', {'class':'siropuChatMessage'}):
- messages.append(i.text)
- for i in range(len(messages)):
- await client.send_message(channel, "%-20s: %s" % (users[i], messages[i]))
- print("%-20s: %s" % (users[i], messages[i]))
- @client.event
- async def on_ready():
- print('Logged in as', client.user.name, client.user.id)
- for server in client.servers:
- print(server.name, server.id)
- if server.id == server_id:
- for chan in server.channels:
- print("\t", chan.name, chan.id)
- print('------')
- @client.event
- async def on_message(message):
- if message.content.startswith('!') and message.author.id == master:
- command = message.content.split()[0][1:]
- args = message.content.split()[1:]
- print(command)
- print(args)
- await client.send_message(message.channel, commands[command](args))
- if message.content.startswith('!test'):
- counter = 0
- tmp = await client.send_message(message.channel, 'Calculating messages...')
- async for log in client.logs_from(message.channel, limit=100):
- if log.author == message.author:
- counter += 1
- await client.edit_message(tmp, 'You have {} messages.'.format(counter))
- elif message.content.startswith('!sleep'):
- await client.send_message(message.channel, 'ZzzzzzZZzzzz')
- await asyncio.sleep(5)
- await client.send_message(message.channel, 'Done sleeping')
- elif message.content.startswith('!whoami'):
- await client.send_message(message.channel, message.author.id)
- def do_add(args):
- try:
- if len(args) >= 2:
- args = list(map(int, args))
- return str(sum(args))
- else:
- return "[ERROR]: Requires at least 2 arguments"
- except:
- return "[ERROR]: Bad input format"
- commands = {'add': do_add}
- with requests.session() as s:
- signal.signal( signal.SIGINT, callback_shutdown ) # register graceful shutdown here
- if len(sys.argv) > 1:
- if sys.argv[1] == "bridge":
- username = login()
- token = getToken(s.get(url_shouty, headers=headers).text)
- client.loop.create_task(showShouty())
- client.run('ENTER DISCORD SECRET BOT API KEY HERE')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement