Guest User

Untitled

a guest
Aug 16th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. #! /usr/bin/python3
  2.  
  3. # Import Built-Ins
  4. import time
  5. import random
  6. import json
  7. import requests
  8. import threading
  9. import traceback
  10. from base64 import b64encode
  11. from os import urandom
  12. from threading import Thread
  13. from functools import lru_cache
  14. import socket
  15. import shutil
  16.  
  17. # Import Third-Party
  18. from abc import ABCMeta, abstractmethod
  19. from skpy import Skype, SkypeNewMessageEvent, SkypeEventLoop, SkypeMsg
  20.  
  21. #python3 -m pip install -U discord.py
  22. import discord
  23. import asyncio
  24.  
  25.  
  26. USERNAME = ""
  27. PASSWORD = ""
  28. #GROUP_URL = 'https://join.skype.com/icRoAW12SZfE'
  29. GROUP_URL = "https://join.skype.com/T2FY7ggzID5k"
  30.  
  31. new_message = []
  32. stick_channel = "relay_bot_test"
  33.  
  34. client = discord.Client()
  35.  
  36. @client.event
  37. async def on_ready():
  38. print("Discord ok")
  39. #print(client.user.name)
  40. #print(client.user.id)
  41. print('------')
  42.  
  43. async def send_new_message(message):
  44. try:
  45. await client.send_message(stick_channel, message)
  46. except Exception as e:
  47. print(e)
  48.  
  49. @client.event
  50. async def on_message(message):
  51. if not str(message.author) == "wojtekjBOT#2057":
  52. if message.content.startswith('!cat'):
  53. try:
  54. await client.send_file(message.channel,"cat.jpg", filename=None, content=None, tts=False)
  55. try:
  56. url = 'http://thecatapi.com/api/images/get?type=jpg&size=med'
  57. response = requests.get(url, stream=True)
  58. with open('cat.jpg', 'wb') as out_file:
  59. shutil.copyfileobj(response.raw, out_file)
  60. del response
  61. except:
  62. print("Error downloading cat")
  63. except Exception as e:
  64. print("Didnt found a cat: "+str(e))
  65.  
  66. elif message.content.startswith('!stick'):
  67. global stick_channel
  68. stick_channel = message.channel
  69. print(message.channel)
  70. await client.send_message(message.channel, "I'm going to spam here!")
  71. else:
  72. print("Discord: "+str(message.content))
  73. push("skype", str(message.author), str(message.content))
  74.  
  75. def push(platform, user, message):
  76. try:
  77. if platform == "skype":
  78. print("Pushing to skype")
  79. global new_message
  80. new_message.append("["+user+"]: "+message)
  81. x.write_message()
  82.  
  83. elif platform == "discord":
  84. print("Pushing to discord")
  85. text = "["+user+"]: "+message
  86. run_until_complete(send_new_message(text)) # BUG HEREEEEEEEE CANT CALL IT
  87.  
  88. except Exception as e:
  89. print("Error in push: "+str(e))
  90.  
  91. class SkypeBot(SkypeEventLoop):
  92. def __init__(self):
  93. super(SkypeBot, self).__init__(USERNAME, PASSWORD)
  94. self.skype = Skype(USERNAME, PASSWORD)
  95. chat_group_id = self.chats.urlToIds(GROUP_URL).get('id')
  96. self.chat_group = self.chats.chat(chat_group_id)
  97. print("Skype ok")
  98.  
  99. def write_message(self):
  100. global new_message
  101. message = new_message.pop(0)
  102. print("Sending skype: " +str(message))
  103. self.chat_group.sendMsg(message)
  104.  
  105. def onEvent(self, event):
  106. if isinstance(event, SkypeNewMessageEvent):
  107. msg = {"username":event.msg.userId, "message_string":event.msg.content}
  108. if msg["username"] != self.userId:
  109. print("Skype:" +msg["message_string"])
  110. push("discord", str(msg["username"]), str(msg["message_string"]))
  111.  
  112. x = SkypeBot()
  113.  
  114. t = threading.Thread(target=x.loop)
  115. t.start()
  116.  
  117.  
  118. #CLIENT_ID = "344449945862144000
  119. client.run('MzQ0NDQ5OTQ1ODYyMTQ0MDAw.DGts6w.GJryM1GoNIoCoCMk6eWvKpgUgGY')
Add Comment
Please, Sign In to add comment