-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatBash.py
46 lines (36 loc) · 1.1 KB
/
ChatBash.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
import hexchat
import subprocess
__module_name__ = "ChatBash"
__module_version__ = "1.0"
__module_description__ = "Use /chatbash to toggle all messages you send being piped to bash"
enabled = False
hooks = list()
def chatbash(word, word_eol, userdata):
global enabled
enabled = not enabled
if enabled:
print ("ChatBash is now enabled")
else:
print ("ChatBash is now disabled")
return hexchat.EAT_HEXCHAT
def send_message(word, word_eol, userdata):
global enabled
if not enabled:
return hexchat.EAT_NONE
message = word_eol[0]
print("> {}".format(message))
output = subprocess.Popen(message, stdout=subprocess.PIPE, shell=True).communicate()[0].decode('UTF-8')
for line in output.split('\n'):
print(line)
return hexchat.EAT_ALL
def on_unload(userdata):
global hooks
for hook in hooks:
if hook is not None:
hexchat.unhook(hook)
del hooks[:]
print("ChatBash unloaded")
hooks.append(hexchat.hook_command("chatbash", chatbash, "Command is /chatbash"))
hooks.append(hexchat.hook_command("", send_message, priority=hexchat.PRI_HIGHEST))
hexchat.hook_unload(on_unload)
print("ChatBash loaded")