Advertisement
Guest User

fixed the text

a guest
Aug 19th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. ####################################
  2. ##Test Bot ##
  3. ##Credit: Char ##
  4. ####################################
  5.  
  6. ##This is where you put your imports
  7. import ch
  8. import requests
  9. import os
  10. import sys
  11. import urllib
  12. import time
  13. import traceback
  14. import json
  15. import re
  16. import cgi
  17. import random
  18. import datetime
  19. import binascii
  20.  
  21. if sys.version_info[0] > 2:
  22. import urllib.request as urlreq
  23. else:
  24. import urllib2 as urlreq
  25.  
  26. ############
  27. ##Variables
  28. API_KEY = "AIzaSyA98i5h1IXWNAKVl9TAAJgxVhFJgBJoLZc"
  29. prefix = "!"
  30. username = input("Username: ")
  31. password = input("Password: ")
  32. rooms = ["yt"]
  33.  
  34.  
  35.  
  36. ###########################################################
  37. ##Startup
  38.  
  39. class bot(ch.RoomManager):
  40. def onInit(self):
  41. self.setNameColor("000000")
  42. self.setFontColor("000000")
  43. self.setFontFace("Arial")
  44. self.setFontSize(11)
  45. self.enableBg()
  46. self.enableRecording()
  47.  
  48. def onConnect(self, room):
  49. self.setNameColor("000000")
  50. self.setFontColor("000000")
  51. self.setFontFace("Arial")
  52. self.setFontSize(9)
  53. self.enableBg()
  54. self.enableRecording()
  55. print("[INFO] Connected to "+room.name)
  56.  
  57. def onReconnect(self, room):
  58. self.setNameColor("000000")
  59. self.setFontColor("000000")
  60. self.setFontFace("Arial")
  61. self.setFontSize(9)
  62. self.enableBg()
  63. self.enableRecording()
  64. print("[INFO] Reconnected to : "+room.name)
  65. room.message("Reconnected")
  66.  
  67. def onDisconnect(self, room):
  68. self.setNameColor("000000")
  69. self.setFontColor("000000")
  70. self.setFontFace("Arial")
  71. self.setFontSize(9)
  72. self.enableBg()
  73. self.enableRecording()
  74. print("[INFO] Disconnected from : "+room.name)
  75.  
  76.  
  77. def onFloodWarning(self, room):
  78. print("[INFO] FloodWarning in : "+room.name)
  79. time.sleep(5)
  80. room.reconnect()
  81.  
  82. def onJoin(self, room, user):
  83. if user.name.lower() not in ignorejoin and greet == True:
  84. nam = user.name.lower()
  85. namm = user.name.title()
  86. room.message("http://fp.chatango.com/profileimg/"+nam[0]+"/"+nam[1]+"/"+nam+"/full.jpg"+" ["+namm+"]"+" has joined the room! ~ ")
  87. lurkers.append(user.name)
  88.  
  89. def onBan(self, room, user, target):
  90. room.message(target.name.title()+" was banned by "+user.name.title())
  91. print("[INFO] "+target.name.title()+" was banned by "+user.name.title()+" in "+room.name.title())
  92.  
  93. def onUnban(self, room, user, target):
  94. room.message(target.name.title()+" has been unbanned by "+user.name.title())
  95. print("[INFO] "+target.name.title()+" was unbanned by "+user.name.title()+" in "+room.name.title())
  96.  
  97.  
  98.  
  99.  
  100.  
  101. def onMessage(self, room, user, message):
  102. msgdata = message.body.split(" ",1)
  103. if len(msgdata) > 1:
  104. cmd, args = msgdata[0], msgdata[1]
  105. else:
  106. cmd, args = msgdata[0],""
  107. cmd=cmd.lower()
  108.  
  109. if len(cmd) >0:
  110. if cmd[0]==prefix:
  111. used_prefix = True
  112. cmd = cmd[1:]
  113. else:
  114. used_prefix = False
  115. else:
  116. return
  117.  
  118. ##########################################################
  119. ##Detection
  120.  
  121. #Detect Message
  122. if not used_prefix:
  123. print(("[TEXT/MESSAGE]"), ("[")+room.name+("]"), user.name, (":"), message.body, (":"), message.ip)
  124.  
  125. #Detect Command
  126. if used_prefix:
  127. print(("[COMMAND]"), ("[")+room.name+("]"), user.name, (":"), cmd, (":"), args, (":"), message.ip)
  128.  
  129. #########################
  130. ##Commands
  131.  
  132.  
  133. if used_prefix and cmd=="say":
  134. if len(args)>0:
  135. room.message(user.name.title()+" told me to say: "+args)
  136. else:
  137. room.message("You didn't say anything moron!")
  138.  
  139.  
  140. elif used_prefix and cmd=="yt" and self.getAccess(user) >=1 and len(args)>0:
  141. try:
  142. string=args.lower()
  143. def search(string):
  144. apikey = API_KEY
  145. api = requests.get("https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&order=relevance&q=%s&safeSearch=none&key=%s" % (string, apikey)).json()
  146. id = api['items'][0]['id']['videoId']
  147. link = "https://www.youtube.com/watch?v=%s" % id
  148. title = api['items'][0]['snippet']['title']
  149. auth = api['items'][0]['snippet']['channelTitle']
  150. try:
  151. return title + " by " + auth + " " + link
  152. except:
  153. return "fucked your shit up"
  154. room.message(search(string))
  155. except:
  156. room.message("You dun fucked up kid")
  157. print(traceback.format_exc())
  158.  
  159.  
  160. ###########################
  161. ##Bot Start Code
  162.  
  163. if __name__ == "__main__":
  164. bot.easy_start(rooms, username, password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement