forked from SamuelMoraesF/CachetNotifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
irc-send.py
executable file
·75 lines (53 loc) · 1.68 KB
/
irc-send.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
68
69
70
71
72
73
74
75
#!/usr/bin/env python
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import irc.client
# If SSL is enabled, import the module
if sys.argv[7] == "true":
import ssl
# Commands to run when the bot is connected to the server
def on_connect(connection, event):
# For all receivers
for receiver in target:
# Verify if is channel
if irc.client.is_channel(receiver):
# Join channel and send message
connection.join(receiver)
for message in messages:
connection.privmsg(receiver, message)
# Else, is an nick
else:
# Send the message
for message in messages:
connection.privmsg(receiver, message.decode('utf8'))
# Quit of the server
connection.quit("Cachet Notify")
# Exit application when disconnect
def on_disconnect(connection, event):
raise SystemExit()
# Define receivers var as global
global target
# Split all receivers by comma
target = sys.argv[5].split(',')
# Defining messages separated by comma
messages = sys.argv[6].split(',,')
# If SSL is enabled
if sys.argv[7] == "true":
# Set SSL Factory with SSL
ssl_factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
# Requirement of the IRC module
reactor = irc.client.Reactor()
# Connect with SSL
c = reactor.server().connect(sys.argv[1], int(sys.argv[2]), sys.argv[3], password=sys.argv[4], connect_factory=ssl_factory)
# Else, SSL is disabled
else:
# Requirement of the IRC module
reactor = irc.client.Reactor()
# Connect to the server
c = reactor.server().connect(sys.argv[1], int(sys.argv[2]), sys.argv[3])
# Define handlers
c.add_global_handler("welcome", on_connect)
c.add_global_handler("disconnect", on_disconnect)
# Define as forever process
reactor.process_forever()