Last active
November 29, 2015 07:33
-
-
Save timawesomeness/f1680f73b3a34b77388b to your computer and use it in GitHub Desktop.
timbot, a simple SSL IRC bot by timawesomeness
This file contains 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
#*********************************************************************************# | |
# timbot v1.1 by timawesomeness # | |
# Requires Python 3 # | |
# Follow the commented instructions to set up; run with 'python timbot.py' # | |
# # | |
# Copyright 2015 timawesomeness # | |
# # | |
# Licensed under the Apache License, Version 2.0 (the "License"); # | |
# you may not use this file except in compliance with the License. # | |
# You may obtain a copy of the License at # | |
# # | |
# http://www.apache.org/licenses/LICENSE-2.0 # | |
# # | |
# Unless required by applicable law or agreed to in writing, software # | |
# distributed under the License is distributed on an "AS IS" BASIS, # | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # | |
# See the License for the specific language governing permissions and # | |
# limitations under the License. # | |
#*********************************************************************************# | |
import socket, ssl, random, datetime | |
server = "" #insert server address here | |
port = #insert SSL port here | |
channels = "", "" #insert channels here as strings separated by commas | |
botnick = "" #insert bot's nick here | |
password = "" #if the server has a password, insert it here | |
def commands(nick, channel, message): | |
msg = decodemsg(message) | |
if msg == ".duck": | |
sendmsg(channel, pickduck()) | |
elif (msg == ".bang") and (channel == "#penguinpower"): | |
sendmsg(channel, nick + " you missed the duck completely.") | |
elif msg == ".bamg": | |
sendmsg(channel, "Learn to type, " + nick) | |
elif message.find(parsetxt(" :.murder ")) != -1: | |
murderee = message.split(parsetxt('.murder '))[1].strip(parsetxt(' ')).decode('UTF-8') | |
if murderee == botnick: | |
murderee = nick | |
nick = botnick | |
sendmsg(channel, murder(nick, murderee)) | |
elif msg == ".timsource": | |
sendmsg(channel, "https://gist.github.com/timawesomeness/f1680f73b3a34b77388b") | |
elif msg == ".nsa": | |
sendmsg(channel, "I’d just like to interject for a moment. What you’re refering to as Windows, is in fact, NSA/Windows, or as I’ve recently taken to calling it, NSA plus Windows. Windows is not an operating system unto itself, but rather another locked down component of a fully functioning NSA system made useful by the NSA corelibs, shell utilities and vital system components comprising a full OS as defined by the government.") | |
elif (msg == ".killbutt") and ((nick == "") or (nick == "")): #insert admin nicks in these strings | |
print("\nKilled by " + nick) | |
quit() | |
def murder(nick, murderee): | |
num = random.randint(0,8) | |
murders = { | |
0: nick + " brutally murders " + murderee + " with a rusty axe.", | |
1: nick + " brutally murders " + murderee + " with a chainsaw.", | |
2: nick + " brutally murders " + murderee + " with a bloody scalpel.", | |
3: nick + " brutally murders " + murderee + " with Winter_Fox.", | |
4: nick + " brutally murders " + murderee + " with a large cleaver.", | |
5: nick + " burns " + murderee + " to death with a napalm flamethrower.", | |
6: nick + " brutally murders " + murderee + " with a nail gun.", | |
7: nick + " brutally murders " + murderee + " using an electric chair.", | |
8: nick + " brutally murders " + murderee + " with a .50 caliber pistol." | |
} | |
return murders[num] | |
def decodemsg(message): | |
return message.split(parsetxt(' :'))[1].decode('UTF-8') | |
def pickduck(): | |
num = random.randint(0,5) | |
ducks = { | |
0: "・゜゜・。。・゜ ゜\_O< QUACK!", | |
1: "・゜゜・。。 ・゜゜\_o< quack!", | |
2: "・゜゜・。。・゜ ゜\_ö< quack!", | |
3: "・゜゜・。。・ ゜゜\_o< FLAP FLAP!", | |
4: "・゜゜ ・。。・゜゜\_ó< quack!", | |
5: "・゜゜・。 。・゜゜\_0< QUACK!" | |
} | |
return ducks[num] | |
def parsetxt(txt): | |
return bytes(txt, 'UTF-8') | |
def send(thing): | |
ircsock.send(parsetxt(thing)) | |
def auth(passwd): | |
send("PASS " + passwd + "\n") | |
def ping(): | |
send("PONG :Pong\n") | |
def sendmsg(chan, msg): | |
print(parsetxt("Sending \"" + msg + "\" to " + chan)) | |
send("PRIVMSG " + chan + " :" + msg + "\n") | |
def joinchan(chans): | |
for chan in chans: | |
send("JOIN " + chan + "\n") | |
def hello(): | |
send("PRIVMSG " + channel + " :・゜゜・。。・゜ ゜\_O< QUACK!\n") | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect((server, port)) | |
ircsock = ssl.wrap_socket(s) | |
auth(password) | |
send("USER " + botnick + " " + botnick + " " + botnick + " :This bot is " + botnick + ", controlled by #INSERTYOURNICKHERE#\n") | |
send("NICK " + botnick + "\n") | |
joinchan(channels) | |
while 1: | |
ircmsg = ircsock.recv(2048) | |
ircmsg = ircmsg.strip(parsetxt('\n\r')) | |
print(parsetxt(datetime.datetime.now().strftime("[%#I:%M:%S %p] ")) + ircmsg) | |
if ircmsg.find(parsetxt(' PRIVMSG ')) != -1: | |
nick = ircmsg.split(parsetxt('!'))[0][1:].decode('UTF-8') | |
channel = ircmsg.split(parsetxt(' PRIVMSG '))[-1].split(parsetxt(' :'))[0].decode('UTF-8') | |
commands(nick, channel, ircmsg) | |
if ircmsg.find(parsetxt("PING :")) != -1: | |
ping() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment