This repository has been archived by the owner on Jun 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtwitch-autoemote.py
241 lines (211 loc) Β· 8.01 KB
/
twitch-autoemote.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# coding=utf-8
import hexchat
import os
import sys
if sys.version_info[0] == 2:
import urllib2 as urllib_error
import urllib as urllib_request
else:
import urllib.error as urllib_error
import urllib.request as urllib_request
__module_name__ = "Twitch Emote Autoformat"
__module_author__ = "Poorchop"
__module_version__ = "0.8"
__module_description__ = "Automatically format TwitchTV emote names with proper capitalization"
# TODO: cross platform support
# TODO: emote unicode character support
# TODO: only load subscriber emotes for subscribed/specified channels
# change this value to False if you do not wish to use subscriber emotes
allow_sub_emotes = True
events = ("Channel Message", "Channel Msg Hilight",
"Channel Action", "Channel Action Hilight",
"Your Message")
edited = False
# emote names taken from: http://twitchemotes.com/
# list last updated August 18, 2014
emote_dict = {'4head': '4Head',
'arsonnosexy': 'ArsonNoSexy',
'asianglow': 'AsianGlow',
'atgl': 'AtGL',
'ativy': 'AtIvy',
'atww': 'AtWW',
'bcwarrior': 'BCWarrior',
'bort': 'BORT',
'batchest': 'BatChest',
'biblethump': 'BibleThump',
'bigbrother': 'BigBrother',
'bionicbunion': 'BionicBunion',
'blargnaunt': 'BlargNaut',
'bloodtrail': 'BloodTrail',
'brainslug': 'BrainSlug',
'brokeback': 'BrokeBack',
'cougarhunt': 'CougarHunt',
'daesuppy': 'DAESuppy',
'dbstyle': 'DBstyle',
'dansgame': 'DansGame',
'datsheffy': 'DatSheffy',
'dogface': 'DogFace',
'eagleeye': 'EagleEye',
'elegiggle': 'EleGiggle',
'evilfetus': 'EvilFetus',
'fpsmarksman': 'FPSMarksman',
'fungineer': 'FUNgineer',
'failfish': 'FailFish',
'frankerz': 'FrankerZ',
'freakinstinkin': 'FreakinStinkin',
'fuzzyotteroo': 'FuzzyOtterOO',
'gasjoker': 'GasJoker',
'gingerpower': 'GingerPower',
'grammarking': 'GrammarKing',
'hassaanchop': 'HassaanChop',
'hassanchop': 'HassanChop',
'hotpokket': 'HotPokket',
'itsboshytime': 'ItsBoshyTime',
'jkanstyle': 'JKanStyle',
'jebaited': 'Jebaited',
'joncarnage': 'JonCarnage',
'kapow': 'KAPOW',
'kzassault': 'KZassault',
'kzcover': 'KZcover',
'kzguerilla': 'KZguerilla',
'kzhelghast': 'KZhelghast',
'kzowl': 'KZowl',
'kzskull': 'KZskull',
'kappa': 'Kappa',
'keepo': 'Keepo',
'kevinturtle': 'KevinTurtle',
'kippa': 'Kippa',
'kreygasm': 'Kreygasm',
'mvgame': 'MVGame',
'mechasupes': 'MechaSupes',
'mrdestructoid': 'MrDestructoid',
'nightbat': 'NightBat',
'ninjatroll': 'NinjaTroll',
'nonospot': 'NoNoSpot',
'omgscoots': 'OMGScoots',
'onehand': 'OneHand',
'opieop': 'OpieOP',
'optimizeprime': 'OptimizePrime',
'pjharley': 'PJHarley',
'pjsalt': 'PJSalt',
'pmstwin': 'PMSTwin',
'panicvis': 'PanicVis',
'pazpazowitz': 'PazPazowitz',
'peopleschamp': 'PeoplesChamp',
'picomause': 'PicoMause',
'pipehype': 'PipeHype',
'pogchamp': 'PogChamp',
'poooound': 'Poooound',
'punchtrees': 'PunchTrees',
'ralpherz': 'RalpherZ',
'redcoat': 'RedCoat',
'residentsleeper': 'ResidentSleeper',
'ritzmitz': 'RitzMitz',
'rulefive': 'RuleFive',
'smorc': 'SMOrc',
'smskull': 'SMSkull',
'ssssss': 'SSSsss',
'shazbotstix': 'ShazBotstix',
'shazam': "Shazam",
'sobayed': 'SoBayed',
'sonnerlater': 'SoonerLater',
'srihead': 'SriHead',
'stonelightning': 'StoneLightning',
'strawbeary': 'StrawBeary',
'supervinlin': 'SuperVinlin',
'swiftrage': 'SwiftRage',
'tf2john': 'TF2John',
'tehfunrun': 'TehFunrun',
'theringer': 'TheRinger',
'thetarfu': 'TheTarFu',
'thething': 'TheThing',
'thunbeast': 'ThunBeast',
'tinyface': 'TinyFace',
'toospicy': 'TooSpicy',
'trihard': 'TriHard',
'uleetbackup': 'UleetBackup',
'unsane': 'UnSane',
'unclenox': 'UncleNox',
'volcania': 'Volcania',
'wtruck': 'WTRuck',
'wholewheat': 'WholeWheat',
'winwaker': 'WinWaker',
'youwhy': 'YouWHY',
'aneleanele': 'aneleanele',
'noscope420': 'noScope420',
'shazamicon': 'shazamicon'}
def parse_sub_emotes(file_path):
f = open(file_path, "r")
for line in f:
stripped_emote = line.replace("\n", "")
lowercase_emote = stripped_emote.lower()
emote_dict[lowercase_emote] = stripped_emote
f.close()
def download_emotes(file_path):
url = "https://raw.githubusercontent.com/Poorchop/hexchat-scripts/master/twitch-sub-emotes.txt"
try:
urllib_request.urlretrieve(url, file_path)
hexchat.prnt("Successfully downloaded subscriber emote list")
parse_sub_emotes(file_path)
except urllib_error.HTTPError as e:
hexchat.prnt("Could not retrieve subscriber emote list ({}), try downloading manually at {} and then reload "
"this script".format(e, url))
if allow_sub_emotes:
file_path = os.path.join(hexchat.get_info("configdir"),
"addons", "twitch-sub-emotes.txt")
if os.path.exists(file_path):
parse_sub_emotes(file_path)
else:
download_emotes(file_path)
def is_twitch():
server = hexchat.get_info("host")
if server and "twitch.tv" in server:
return True
else:
return False
def keypress_cb(word, word_eol, userdata):
key = word[0]
mod = word[1]
# a ctrl backspace
if (key, mod) == ("97", "4") or key == "65288":
return
if is_twitch():
msg = hexchat.get_info("inputbox")
if msg:
split_words = msg.split(" ")
for w in split_words:
if w.lower() in emote_dict:
split_words[split_words.index(w)] = emote_dict[w.lower()]
new_msg = " ".join(split_words)
hexchat.command("SETTEXT {}".format(new_msg))
hexchat.command("SETCURSOR {}".format(len(new_msg)))
def emote_cb(word, word_eol, event):
word = [(word[i] if len(word) > i else "") for i in range(4)]
global edited
if edited:
return
if is_twitch():
word[1] = word[1] \
.replace(":)", "π") \
.replace(":(", "βΉ") \
.replace(":z", "π΄") \
.replace("B)", "π") \
.replace(";)", "π") \
.replace(";p", "π") \
.replace(":p", "π") \
.replace(":D", "π") \
.replace(">(", "π ") \
.replace("<3", "β₯") \
.replace("BionicBunion", "πΊ") \
.replace("FrankerZ", "πΆ") \
.replace("ItsBoshyTime", "β ") \
.replace("Kappa", "π") \
.replace("KZskull", "π")
edited = True
hexchat.emit_print(event, *word)
edited = False
return hexchat.EAT_ALL
hexchat.hook_print("Key Press", keypress_cb)
for event in events:
hexchat.hook_print(event, emote_cb, event, priority=hexchat.PRI_HIGH)
hexchat.prnt(__module_name__ + " version " + __module_version__ + " loaded")