-
Notifications
You must be signed in to change notification settings - Fork 2
/
Python_bot.py
70 lines (56 loc) · 1.87 KB
/
Python_bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sys
import socket
import time
import math
#simple PING-PONG function
def ppong():
while 1:
text=b""
text=irc.recv(8000)
print(text)
if text.find(b"PING") !=-1:
irc.send(b"PONG "+text.split()[1]+b"\r\n")
break
def reply():
irc.send(b"PRIVMSG "+target+ b":!Your Mssg\r\n") #send private message to your target
while 1:
text=b""
text=irc.recv(8000)
print(text)
if text.find(b"/")>-1:
try:
text=text[(text[1:].find(b":"))+2:] # to slice string message from (:){excluding} to next 2 numbers/text...
text=text[:text.find(b".")] # to slice from start to end exluding everything
print(text)
break
except:
print(b"Waiting for quextion....")
# Filling form ,hence define global var
host =" " #for host (optional)
server =" " #for server/host to connect
botnick =" " #bot identification name
channel =" " #channel to join
ident =" " #(optional)
realname =" " #(optional)
target =" " #(optional)for user/bot
port = #6667
#Establisihng connection...
#filling form...
try:
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc.connect((server,port))
except:
print("! Can`t connect!")
else:
irc.send("USER "+botnick+" "+botnick+" "+botnick+" :My Bot!\r\n")
irc.send("NICK "+botnick+"\n")
irc.send("JOIN "+channel+"\n")
time.sleep(1)
print("ping:pong")
ppong()
print("reply") #define functions to increase bot interaction
reply()
print("good day:")
irc.close() #close command
# more robust approach but nonetheless gets thing done for our challenge
#taken from 0day blog -try/except for error handling at connextion time