-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatoscript.py
88 lines (72 loc) · 2.94 KB
/
gatoscript.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
# -*- coding: UTF8 -*-
# CopyRight (C) 2006-2013 GatoLoko
#
# This file is part of GatoScript
#
# GatoScript is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# GatoScript is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GatoScript; if not, see <http://www.gnu.org/licenses/>.
"""
GatoScript's main module.
"""
__module_name__ = "GatoScript"
__module_description__ = "GatoScript for HexChat and X-Chat "
__module_autor__ = "GatoLoko"
# To interact with X-Chat/HexChat
import xchat
# To manage folders
from os.path import join
import sys
# Define environment variables
scriptdir = xchat.get_info("xchatdir")
moddir = join(scriptdir, "gatoscript")
# Incluide out modules directory in the path
sys.path.append(moddir)
xchat.command('menu -p4 ADD "GatoScript"')
# Load all the script modules
import gmodules
__module_version__ = gmodules.helper.__module_version__
def help_cb(word, word_eol, userdata):
gmodules.helper.gprint("GatoScript help:")
for entry in dir(gmodules):
if "__" not in entry:
command = ''.join(["gmodules.", entry, ".ghelp()"])
messages = eval(command)
for message in messages:
gmodules.helper.gprint(message)
#############################################################################
# Script unloading function.
#############################################################################
def unload_cb(userdata):
xchat.unhook(HOOKGHELP)
for entry in dir(gmodules):
# Since helper module isn't directly loaded, it doesn't neet to be
# directly unloaded either
if "__" not in entry and entry is not "helper":
command = ''.join(["gmodules.", entry, ".unload()"])
messages = eval(command)
if messages:
for message in messages:
print(message)
xchat.unhook(HOOKUNLOAD)
xchat.command('menu del GatoScript')
print("".join(["GatoScript ", __module_version__, " has been unloaded"]))
#############################################################################
# Hooks for all functions provided by this module
#############################################################################
help_usage = "Usage: ghelp, shows GatoScript help"
HOOKGHELP = xchat.hook_command("gatohelp", help_cb, help=help_usage)
HOOKUNLOAD = xchat.hook_unload(unload_cb)
# If this point is reached, it means the script has been loaded succefully, so
# we anounce it.
message = "".join(["GatoScript ", __module_version__, " has been loaded."])
gmodules.helper.gprint(message)