Skip to content

Instantly share code, notes, and snippets.

@antdking
Created July 3, 2014 16:36
Show Gist options
  • Save antdking/3a85d603bbc4bbeae341 to your computer and use it in GitHub Desktop.
Save antdking/3a85d603bbc4bbeae341 to your computer and use it in GitHub Desktop.
# Copyright (C) 2013 Cybojenix
# This may not be distirubuted or modified without concent from the author
__AUTHOR__ = "Cybojenix"
__COPYRIGHT__ = "Cybojenix"
__LICENSE__ = "None"
from watchdog.observers import Observer
from watchdog.tricks import Trick
from re import sub
import socket, ssl
from time import sleep
watch_path = "testing"
usern = "gfgfbfgb"
fbg = "vfgbhddgbghnfbfgbfgbcghk"
passw = ":".join([usern, fbg])
host = "454.652.545.122"
port = 4354
channel = u'\x7E\x23bfgb-bgfbgh'
s = socket.socket(socket.AF_INET, socket.TCP_NODELAY)
s.connect((host, port))
irc = ssl.wrap_socket(s)
def connect_irc():
irc.send("NICK %s\r\n" % usern)
irc.send("USER {user} :gfgfbfgb\n".format(user=usern))
irc.send("PASS " + passw + "\r\n")
def format_message(message):
new_message = sub('^\[.*\] ', '', message)
return new_message
def get_message(monitored_file):
with open(monitored_file, "r") as f:
message = f.readlines()[-1]
return format_message(message)
def send_message(message):
irc.send("PRIVMSG " + channel + " :" + message + "\r\n")
def register_watcher():
event_handler = PushMessage(patterns=["*"])
global observer
observer = Observer()
observer.schedule(event_handler,
path=watch_path)
observer.start()
class PushMessage(Trick):
def on_any_event(self, event):
message = get_message(event.src_path)
send_message(message)
print message
def restart():
irc.send("PRIVMSG " + channel + " :restarting..\r\n")
observer.stop()
observer.join()
register_watcher()
irc.send("PRIVMSG " + channel + " :done\r\n")
def main():
connect_irc()
print "connected"
sleep(2)
irc.send("JOIN " + channel + "\r\n")
register_watcher()
while 1:
data = irc.recv(4096).strip('\r\n')
print data
if data.find('PING') != -1:
irc.send('PONG ' + data.split() [ 1 ] + '\r\n')
if data.find('.restart') != -1:
restart()
#irc.send("PRIVMSG " + channel + " : closing connection\n")
#irc.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment