Skip to content

Instantly share code, notes, and snippets.

@jwhonce
Created September 30, 2015 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwhonce/aaf51a27ac0e9022ae60 to your computer and use it in GitHub Desktop.
Save jwhonce/aaf51a27ac0e9022ae60 to your computer and use it in GitHub Desktop.
Send NOTICE message to IRC server
#!/usr/bin/python
import socket
import sys
from datetime import datetime
try:
import json
except:
import simplejson as json
print len(sys.argv)
if len(sys.argv) != 2:
sys.exit(0)
with open(sys.argv[1]) as payload:
announcements = json.load(payload)
notices = []
for announce in announcements:
notices.append('NOTICE {0} :{1} -- {2}\r\n'.format(announce['channel'], announce['nicks'], announce['message']))
network = 'porky.str.redhat.com'
port = 6667
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( network, port ) )
print irc.recv ( 4096 )
irc.send ( 'NICK nagbot\r\n' )
irc.send ( 'USER nagbot nagbot nagbot :Python IRC\r\n' )
irc.send ( 'JOIN #jhonce\r\n' )
for notice in notices:
print notice
irc.send(notice)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment