Advertisement
Guest User

Untitled

a guest
Nov 1st, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. #! /usr/bin/env python3
  2.  
  3. import os
  4. import re
  5. import ssl
  6. import sys
  7. #import bs4 # apt-get install python3-bs4
  8. import time
  9. import json
  10. import socket
  11. import string
  12. import threading
  13. import subprocess
  14.  
  15. # Setup the IRC connection
  16. irc = socket.socket()
  17. irc = ssl.wrap_socket(irc)
  18.  
  19. # List of currently active threads
  20. threadlist = []
  21.  
  22. # Edit these values for your server
  23. ircServer = "irc.blackcatz.org"
  24. ircSSLPort = 6697
  25. ircNick = "[Z]NotifyMaster2"
  26. ircPass = "bob"
  27. # What the bot uses as a command character
  28. ircCKey = ircNick
  29. # List of channels to connect to
  30. channelList = ['#bots']
  31. owner = "eve"
  32. # Radio link
  33. radioLink = "https://radio.zempirians.com"
  34. # Bot help command
  35. botList = ['[Z]NotifyMaster','Contains basic help command and notifies bot owners when their bot is down','help'
  36. ,'+[Z]Citadel','Searches for the databases in which your string is found','!email string'
  37. ,'+[Z]Googler','Searches google with the given string, gives you the top result','[Z]Googler: help'
  38. ,'+[Z]MEGABOT','Contains multiple helpful commands that didn\'t require their own bot','[Z]MEGABOT: help'
  39. ,'+[Z]RadioBot','Manages the radio on '+radioLink+'!','[Z]RadioBot: help'
  40. ,'+[Z]RssFeeder','Automatically posts new articles from websites we are subscribed to','[RssFeeder]: help'
  41. ,'+[Z]Titler','Automatically pulls the title of links posted in the chat','[Z]Titler: help'
  42. ,'&Zempire','Administrative bot for the operators','[Z]Zempire: help'
  43. ]
  44. rules = ['[Z] represents a bot, +[Z] represents an official bot and & represents an administrative bot.'
  45. ,'The command \"[Z]BotName: help\" allows you to get the commands of a bot.'
  46. ,'Don\'t make mom jokes. Only Bulwark\'s mom can get those.'
  47. ]
  48. helpList = ['help','Displays the help command of bot and the other general bot commands.'
  49. ,'radio','Returns the radio link.'
  50. ,'die','Kills the bot, if your the owner.'
  51. ]
  52.  
  53. def rawSend(data):
  54. print(str(data+"\r\n").encode())
  55. irc.send(str(data+"\r\n").encode())
  56.  
  57. def ircConnect():
  58. irc.connect((ircServer, ircSSLPort))
  59.  
  60. def ircMessage(msg, channel):
  61. rawSend("PRIVMSG " + channel + " :" + msg + "\r\n")
  62.  
  63. def ircRegister():
  64. rawSend("USER " + ircNick + " 0 * " + ":" + ircNick + "\r\n")
  65.  
  66. def ircSendNick():
  67. rawSend("NICK " + ircNick + "\r\n")
  68.  
  69. def ircJoin(channel):
  70. rawSend("JOIN " + channel + "\r\n")
  71.  
  72. def ircPassword():
  73. rawSend("PASS " + ircPass + "\r\n")
  74.  
  75. def ircDisconnect(msg):
  76. rawSend("QUIT " + msg + "\r\n")
  77.  
  78. def msgFind(msg, data):
  79. return bytes(msg,"utf-8") in data
  80.  
  81. def msgAnalyze(msg, data):
  82. return (msgFind(msg, data) and msgFind(ircNick,data))
  83.  
  84. def Initialize():
  85. time.sleep(5)
  86. ircConnect()
  87. ircRegister()
  88. ircSendNick()
  89.  
  90. def channelRequests(channel, data):
  91. user = str(data).split('!')[0].split(':')[1]
  92. if msgAnalyze("help", data):
  93. #if bytes("help","utf-8") not in data.split()[len(data.split())-1]:
  94. #user = re.match(r"\w+",str(str(data).split()[len(data.split())-1])).group()
  95. ircMessage(user+": look at your private messages!", channel)
  96. ircMessage("General rules:", user)
  97. for z in range(len(rules)):
  98. ircMessage("Rule "+str(int(z)+1)+": "+rules[z], user)
  99. ircMessage("General bots:", user)
  100. for z in range(0,len(botList)-1,3):
  101. ircMessage("Bot: "+str(botList[z])+", description: "+str(botList[z+1])+", main command: "+str(botList[z+2]), user)
  102. ircMessage(ircNick+"'s commands:", user)
  103. for z in range(0,len(helpList),2):
  104. ircMessage("Command: "+helpList[z]+", Function: "+helpList[z+1], user)
  105. elif msgAnalyze("radio", data):
  106. ircMessage("Tune in here: "+radioLink+"!", user)
  107.  
  108. Initialize()
  109. print("Connected.")
  110. while True:
  111. data = irc.recv(512)
  112. if len(str(data)) is not 3:
  113. print(data)
  114. else:
  115. irc.close()
  116. irc = socket.socket()
  117. irc = ssl.wrap_socket(irc)
  118. Initialize()
  119. if str(data)[2:8] == "PING :":
  120. #b'PING :`b@VTMj`\\q\r\n:
  121. rawSend(str(data).split(r"\r\n")[0].replace("IN", "ON").split("b\'")[1].replace("",""))
  122. continue
  123. if msgFind("MODE "+ircNick, data) and msgFind("PRIVMSG", data) is False and msgFind("SSL", data):
  124. #Nick confirmed
  125. time.sleep(1)
  126. ircMessage("IDENTIFY "+ircPass, "NickServ")
  127. for channel in channelList:
  128. ircJoin(channel)
  129. continue
  130.  
  131. for channel in channelList:
  132. if msgFind("PRIVMSG " + channel, data) or msgFind("PRIVMSG " + ircNick, data): #Should be fixed!
  133. if msgFind("PRIVMSG" + ircNick, data):
  134. t = threading.Thread(target=channelRequests, args=(ircNick, data))
  135. else:
  136. t = threading.Thread(target=channelRequests, args=(channel, data))
  137. t.daemon = True
  138. t.start()
  139. continue #Break?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement