forked from surskitt/gtsnotifier_flask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
irccat.py
45 lines (32 loc) · 1.07 KB
/
irccat.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
#! /usr/bin/env python
# Modified from irccat.py
# Original author
# Joel Rosdahl <joel@rosdahl.net>
import sys
import argparse
import itertools
import irc.client
import irc.logging
class ConnectionCallbacks(object):
def __init__(self, target, message):
self.state = "Connecting"
self.target = target
self.message = message
def on_connect(self, connection, event):
self.state = "Connected"
connection.privmsg(self.target, self.message)
connection.quit("")
def on_disconnect(self, connection, event):
self.state = "Disconnected"
def send_message(args):
client = irc.client.IRC()
try:
c = client.server().connect(args["server"], args["port"], args["nickname"])
except irc.client.ServerConnectionError:
print(sys.exc_info()[1])
return False
cc = ConnectionCallbacks(args["target"], args["message"])
c.add_global_handler("welcome", cc.on_connect)
c.add_global_handler("disconnect", cc.on_disconnect)
while cc.state != "Disconnected":
client.process_once(0.2)