-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathirc.py
More file actions
119 lines (97 loc) · 3.92 KB
/
irc.py
File metadata and controls
119 lines (97 loc) · 3.92 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import credentials
import irc_commands
import logging
import mssql_commands
import os
import pyodbc
import string
import socket
import subprocess
import sys
import twitch_commands
import wordpress_commands as wordpress
from time import gmtime, strftime
#Add !roll d#
RUNNING = True
SELF_CHECK = False
FORMATTER_LENGTH = 120
channel = credentials.IRC_CHANNEL
server = credentials.IRC_HOST
minutes_modulator = 10
DETACHED_PROCESS = 0x00000008
logging.basicConfig(level=logging.DEBUG,
format='[%(levelname)s] (%(threadName)-10s) %(message)s',
)
#begin session
s = socket.socket()
s.connect((server, credentials.IRC_PORT))
s.send("PASS " + credentials.IRC_OAUTH_PASSWORD + "\r\n")
s.send("NICK " + credentials.IRC_NICK + "\r\n")
s.send("JOIN #" + channel + " \r\n")
def Send_message(message):
s.send("PRIVMSG #" + channel + " :" + message + "\r\n")
Terminal(message)
def Terminal(message):
message = message.replace('\n','').replace('\r','').strip()
now = strftime("%Y-%m-%d %H:%M:%S", gmtime())
message = now + ": " + message
while(len(message) > FORMATTER_LENGTH):
for n in range(0, FORMATTER_LENGTH):
if(message[FORMATTER_LENGTH-n] == " "):
break
print message[0:FORMATTER_LENGTH-n]
message = (" "*len(str(now))) + " " + message[FORMATTER_LENGTH-n:len(message)]
print message
Send_message("I have returned!")
while(RUNNING):
#try:
ircmsg = s.recv(1024).strip('\r\n')
if (ircmsg != ""):
if (ircmsg.startswith("PING :tmi.twitch.tv")):
s.send("PONG :tmi.twitch.tv\r\n")
Terminal(ircmsg)
Terminal("PONG :tmi.twitch.tv")
elif((ircmsg.startswith(":tmi.twitch.tv")) or (ircmsg.startswith(":forcethestorm"))):
for item in ircmsg.split('\n'):
Terminal(item)
else:
username = ircmsg.split("!")[0].split(":")[1]
message_recieved = ircmsg.split("PRIVMSG #" + channel)[1]
Terminal("#" + channel + ": " + username + message_recieved)
#update_last_seen(user, time)
if (ircmsg.find("PRIVMSG #" + channel + " :!") != -1):
if (ircmsg.find(":!card") != -1):
card = ircmsg.split(":!card ")[1]
Send_message("@" + username + " " + card + ": " + mssql_commands.Get_Oracle_Text(card))
elif ((ircmsg.find(":!quit") != -1) and (username == channel)):
#end session
os._exit(0)
elif ((ircmsg.find(":!restart") != -1) and (username == channel)):
subprocess.Popen('python irc.py')
os._exit(0)
elif ((ircmsg.find(":!uf") != -1) and (username == channel)):
#subprocess.Popen(["C:\Python27\Lib\idlelib\idle.pyw", "update_twitch_followers.py"], creationflags=DETACHED_PROCESS)
os.system('python update_twitch_followers.py')
elif (ircmsg.find(":!decklist") != -1):
Send_message(mssql_commands.Get_Decklists())
elif (ircmsg.find(":!deck") != -1):
deck_name = ircmsg.split(":!deck ")[1]
deck_url = mssql_commands.Get_WordPress_Decklist(deck_name)
if(deck_url != -1):
Send_message("@" + username + " Deck \"" + deck_name + "\": " + deck_url)
else:
Send_message("@" + username + "Deck \"" + deck_name + "\" not found. Please use !decklists for a list of available decks.")
elif (ircmsg.find(":!article") != -1):
Send_message("New article up! Check it out at: " + wordpress.Get_Last_Article())
elif (ircmsg.find(":!music") != -1):
Send_message("Currently playing: " + irc_commands.Get_Music())
elif (ircmsg.find(":!twitter") != -1):
Send_message("Follow me on Twitter: " + irc_commands.Get_Twitter())
elif (ircmsg.find(":!website") != -1):
Send_message("Check out the website here! " + irc_commands.Get_Website())
elif (ircmsg.find(":!craig") != -1):
Send_message("All praise Craig in his majestic glory!")
#craig = mssql_commands.Get_Total_Craigs()
#Send_message("Craig has deemed us worthy of his presence ? times", craig)
#except:
#print "Something broke."