· 5 years ago · Dec 05, 2020, 09:44 PM
1#!/usr/bin/python
2#-*- coding:utf-8 -*-
3
4##### README #####
5### Prevents text flood from the input box.
6### Pops up a warning if one tries to enter too much text at once (purposefully or accidentally),
7### and asks if it must proceed.
8### ~
9### Load this script with the command:
10### load [PATH/]antiflood.py
11### (file path is required)
12### If a reload is needed, unload the script PRIOR to loading it again (can't load twice):
13### unload antiflood.py
14### (no path needed to unload)
15
16__module_name__ = "antiflood.py"
17__module_version__ = "2020.12.06"
18__module_description__ = "Prevents text flood from the input box"
19__module_author__ = "Thierry Girard"
20### Satisfied or not, no refund!
21
22
23
24#> Here are some of the decoration codes:
25#> ======================================
26#> When using the Perl API for Xchat use the \xxx, in a chat window use the %x.
27#> \002 0x02 %B bold
28#> \007 0x07 - beep
29#> \010 0x0a - hidden
30#> \00307 0x03 %C07 foreground colour
31#> \00307,00 0x03 %C07,00 foreground and background colour
32#> \017 0x0f %O reset
33#> \026 0x16 %R reverse foreground and background
34#> \035 0x1d - italic (new)
35#> \037 0x1f %U underline
36#> = Color codes for X-Chat = = mIRC codes =
37#> ========================== ==============
38#> 00 = black # 0 white # RGB(255, 255, 255)
39#> 01 = white # 1 black # RGB(0, 0, 0)
40#> 02 = blue (navy) # 2 blue (navy) # RGB(0, 0, 127)
41#> 03 = green # 3 green # RGB(0, 127, 0)
42#> 04 = orange # 4 red # RGB(255, 0, 0)
43#> 05 = red # 5 brown (maroon) # RGB(127, 0, 0)
44#> 06 = purple # 6 purple # RGB(127, 0, 127)
45#> 07 = brown # 7 orange (olive) # RGB(255, 127, 0)
46#> 08 = yellow # 8 yellow # RGB(255, 255, 0)
47#> 09 = light green (lime) # 9 lt.green (lime) # RGB(0, 255, 0)
48#> 10 = teal # 10 teal (a kinda green/blue cyan) # RGB(64, 128, 128)
49#> 11 = light cyan (aqua) # 11 lt.cyan (cyan ?) (aqua) # RGB(0, 255, 255)
50#> 12 = light blue # 12 lt.blue (royal) # RGB(0, 0, 255)
51#> 13 = light purple (lilac) # 13 pink (light purple) (fuchsia) # RGB(255, 0, 255)
52#> 14 = grey # 14 grey # RGB(92, 92, 92)
53#> 15 = light grey (silver) # 15 lt.grey (silver) # RGB(184, 184, 184)
54
55
56########################
57### IMPORTs & CONFIG ###
58########################
59
60### color codes
61rouge = "\0034"
62orange = "\0037"
63jaune = "\0038"
64vert = "\0039"
65bleu = "\00312"
66gris = "\00314"
67violet = "\0036"
68none = ""
69
70
71client = "HEXCHAT"
72try:
73 import hexchat as xchat
74except ImportError:
75 try:
76 client = "XCHAT"
77 import xchat
78 except ImportError:
79 print(rouge+"Failed to import 'hexchat' module")
80
81from os import system
82
83#####################################
84### CALLBACK functions from hooks ###
85#####################################
86
87def on_any(word, word_eol, userdata):
88 # Enter Key has, oddly, the code string '65293'
89 if word[0] == '65293':
90 inputbox = xchat.get_info("inputbox")
91 num_chars = len(inputbox)
92 if num_chars > 1024:
93 zen_line = 'zenity --question --width=512 --text="You have tried to enter %i characters at once.\nDo you want to proceed?"' % num_chars
94 retvalue = system(zen_line)
95 if retvalue:
96 return xchat.EAT_ALL
97 return xchat.EAT_NONE
98
99########################################
100### HOOKs on command, print & server ###
101########################################
102
103xchat.hook_print("Key Press",on_any)
104
105### This is executed each time the script is loaded
106print(vert + __module_name__ + " " + __module_version__ + " loaded")
107
108### This is called whenever the script is unloaded
109def unload_cb(userdata):
110 print(vert + __module_name__ + " " + __module_version__ + " being unloaded")
111
112xchat.hook_unload(unload_cb)
113
114#server = xchat.get_info("server")
115#c_server = xchat.find_context(channel=server)
116#c_server.command('echo ' + bleu + 'Hello ' + orange + 'World' + rouge + ' :)')