Created
February 13, 2019 09:48
-
-
Save iGlitch/a5249052a401652a2c35d536148b8c10 to your computer and use it in GitHub Desktop.
Super basic IRC bot in Python
This file contains hidden or 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
import os | |
import re | |
import socket | |
import httplib | |
import random | |
import sys | |
import time | |
from datetime import date | |
import urllib | |
import cgi | |
import cgitb | |
cgitb.enable() | |
def sendm(msg): | |
irc.send('PRIVMSG '+channel+' :'+str(msg)+'\r\n') | |
channel= '#glitch' | |
network = 'irc.stormbit.net' | |
port = 6667 | |
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM ) | |
irc.connect ( ( network, port ) ) | |
print irc.recv ( 4096 ) | |
irc.send ( 'NICK GlitchBOT\r\n' ) | |
irc.send ( 'USER GlitchBOT GlitchBot GlitchPython :GlitchBOT\r\n' ) | |
irc.send ( 'JOIN #glitch\r\n' ) | |
irc.send ( 'PRIVMSG #glitch :Hello World.\r\n' ) | |
while True: | |
data = irc.recv ( 4096 ) | |
if data.find ( 'PING' ) != -1: | |
irc.send ( 'PONG ' + data.split() [ 1 ] + '\r\n' ) | |
if data.find ( '!quit' ) != -1: | |
irc.send ( 'PRIVMSG #glitch :Goodbye cruel world...\r\n' ) | |
irc.send ( 'QUIT\r\n' ) | |
if data.find ( 'hi GlitchBot' ) != -1: | |
irc.send ( 'PRIVMSG #glitch :I already said hi...\r\n' ) | |
if data.find ( 'hello GlitchBot' ) != -1: | |
irc.send ( 'PRIVMSG #glitch :I already said hi...\r\n' ) | |
if data.find ( 'KICK' ) != -1: | |
irc.send ( 'JOIN #glitch\r\n' ) | |
if data.find ( 'cheese' ) != -1: | |
irc.send ( 'PRIVMSG #glitch :WHERE!!!!!!\r\n' ) | |
if data.find ( 'slaps glitch' ) != -1: | |
irc.send ( 'PRIVMSG #glitch :This is the Trout Protection Agency. Please put the Trout Down and walk away with your hands in the air.\r\n' ) | |
print data | |
if data.find (':!time') != -1: | |
sendm('[+] The current local time is: '+time.strftime("%H:%M:%S", time.localtime())) | |
if data.find (':!date') != -1: | |
sendm('[+] Today\'s date is: '+time.strftime("%a, %b %d, %y",time.localtime())) | |
if data.find(':!wiki') != -1: | |
wiki= data.split(':!wiki') | |
wikis=wiki[1].strip() | |
if len(wikis) < 1: | |
sendm('[+] Error! Example: !wiki Glitch') | |
else: | |
sendm('[+] Wiki: http://www.wikipedia.org/wiki/'+str(wikis)) | |
if data.find(':!voice') != -1: | |
voice = data.split('!voice') | |
voices = voice[1].strip() | |
irc.send('MODE '+str(channel) +' +v '+str(voices) +'\r\n') | |
if data.find(':!devoice') != -1: | |
devoice = data.split(':!devoice') | |
devoices = devoice[1].strip() | |
irc.send('MODE '+ str(channel) +' -v '+ str(devoices) +'\r\n') | |
if data.find(':!op') != -1: | |
op = data.split('!op') | |
ops = op[1].strip() | |
irc.send('MODE '+str(channel) +' +op '+str(ops) +'\r\n') | |
if data.find(':!deop') != -1: | |
deop = data.split(':!deop') | |
deops = deop[1].strip() | |
irc.send('MODE '+ str(channel) +' -op '+ str(deops) +'\r\n') | |
if data.find(':!hop') != -1: | |
hop = data.split('!hop') | |
hops = hop[1].strip() | |
irc.send('MODE '+str(channel) +' +hop '+str(hops) +'\r\n') | |
if data.find(':!dehop') != -1: | |
dehop = data.split(':!dehop') | |
dehops = dehop[1].strip() | |
irc.send('MODE '+ str(channel) +' -hop '+ str(dehops) +'\r\n') | |
if data.find(':!dns' ) != -1: | |
try: | |
dns = data.split(':!dns' ) | |
dnsget = dns[1].strip() | |
dnserv = socket.gethostbyaddr(dnsget) | |
irc.send ( 'PRIVMSG '+ chan +' :Address : '+ str(dnserv) +'\n' ) | |
except: | |
irc.send ( 'PRIVMSG '+ chan +' :[ERROR] Something is wrong here!!!\n' ) | |
if data.find(':!join') != -1: | |
joins = data.split(':!join') | |
das = joins[1].strip() | |
irc.send('JOIN '+ str(das) +'\r\n') | |
if data.find(':!nick') != -1: | |
nickname = data.split(':!nick') | |
if len(nickname) < 2: | |
pass | |
else: | |
nicknames = nickname[1].strip() | |
irc.send('NICK '+ str(nicknames) +'\r\n') | |
if data.find(':!topic') != -1: | |
topi = data.split(':!topic') | |
topic = topi[1].strip() | |
irc.send('TOPIC #glitch :'+ str(topic) +'\r\n') | |
if topic == topic: | |
sendm('[+] Topic change') | |
if data.find(':!image') != -1: | |
image = data.split(':!image') | |
images = image[1].strip() | |
if len(images) < 1: | |
sendm('[+] Error! Example: !image glitch') | |
else: | |
sendm('[+] Google Images: http://images.google.com/images?um=1&hl=en&q='+ images +'&btnG') | |
if data.find(':!pb') != -1: | |
image = data.split(':!pb') | |
images = image[1].strip() | |
if len(images) < 1: | |
sendm('[+] Error! Example: !image glitch') | |
else: | |
sendm('[+] Photobucket Images: http://photobucket.com/images/'+ images) | |
if data.find(':!newyear') != -1: | |
now = date.today() | |
newyear = date(2011, 12, 31) | |
cik = newyear - now | |
newyears = cik.days | |
sendm('[+] Days left until new years: '+ str(newyears)) | |
if data.find(':!magic8') != -1: | |
n = random.randint(1, 7) | |
if n == 1: | |
sendm('The answer lies within your heart') | |
if n == 2: | |
sendm('I do not know') | |
if n == 3: | |
sendm('Almost certainly') | |
if n == 4: | |
sendm('No') | |
if n == 5: | |
sendm('Why do you need to ask?') | |
if n == 6: | |
sendm('Go away. I do not wish to answer at this time.') | |
if n == 7: | |
sendm('Time will only tell') | |
if data.find(':!coin') != -1: | |
n = random.randint(1, 2) | |
if n == 1: | |
sendm('Heads') | |
if n == 2: | |
sendm('Tails') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment