Created
July 22, 2019 21:27
-
-
Save doyousketch2/0ec47ce494faeb14c10483bde4afdd33 to your computer and use it in GitHub Desktop.
Auto grant OP and VOICE in HexChat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://git.io/fjDec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##========================================================= | |
## @Doyousketch2 AGPL-3 Jul 2, 2019 | |
## https://www.gnu.org/licenses/agpl-3.0.en.html | |
##========================================================= | |
## header | |
__module_name__ = 'auto_op.py' | |
__module_version__ = '2.6' | |
__module_description__ = 'Auto grant OP and VOICE in HexChat' | |
author = '@Doyousketch2' | |
import hexchat | |
import requests | |
import bs4 | |
## print info, so you know it's loaded | |
info = ( __module_name__, __module_version__, __module_description__, author ) | |
hexchat .prnt( '{}, ver. {} loaded.\n {}\n {}' .format( *info ) ) | |
##========================================================= | |
''' notes: written in Python 3 | |
sudo pip3 install bs4 requests | |
https://hexchat.readthedocs.io/en/latest/script_python.html | |
For example on a “Channel Message” event: | |
[23:29:26] <@Nick> hello everyone | |
word[0] is Nick | |
word[1] is hello everyone | |
word[2] is @ | |
word_eol[0] is Nick hello everyone @ | |
word_eol[1] is hello everyone @ | |
word_eol[2] is @ | |
''' | |
##========================================================= | |
## variable declaration | |
print_debug_msgs = False ## set to True if you want to see excess jibberish. | |
debug_text = __module_name__ +' dbg {} ||{}||' ## script_name dbg variable ||value|| | |
CHANNELS = ( '#IHN', '#testing_testing' ) | |
OP = ( 'DutchessPyle', 'LadyPyle', 'Sketch2', 'nri', 'catspar' ) | |
Safe_OP_Locations = ( 'ph.ph.cox.net', 'columbus.res.rr.com' ) | |
## HALFOP = ( ) ## no such thing on Freenode | |
VOICE = ( 'deezl', 'annette', 'gameminer', 'meme_queen', 'Sirus', 'Nezrok', 'okey', 'Tomraceror' ) | |
last_3_msgs = [ ] | |
##========================================================= | |
## define functions | |
def send_last3( NAME ): ## print out the last three messages to people who just recently showed up | |
''' | |
length = len( last_3_msgs ) | |
if length > 1: | |
text = 'msg {} wb. Last {} msgs from chat:' .format( NAME, length ) | |
hexchat .prnt ( text ) | |
##hexchat .command( text ) | |
for msg in range( length ): | |
text = 'msg {} {}' .format( last_3_msgs[msg][0], last_3_msgs[msg][1] ) | |
hexchat .prnt ( text ) | |
##hexchat .command( text ) | |
elif length > 0: | |
text = 'msg {} wb. Last {} msg from chat:' .format( NAME, length ) | |
hexchat .prnt ( text ) | |
##hexchat .command( text ) | |
text = 'msg {} {}' .format( last_3_msgs[0][0], last_3_msgs[0][1] ) | |
hexchat .prnt ( text ) | |
##hexchat .command( text ) | |
''' | |
def store_three_and_print_urls( word, word_eol, userdata ): | |
NICK = word[0] | |
MSG = word[1] | |
# FLAGS = word[2] | |
CHAN = hexchat .get_info( 'channel' ) | |
if CHAN in CHANNELS: | |
last_3_msgs .insert( 0, [NICK, MSG] ) | |
if len( last_3_msgs ) > 3: | |
last_3_msgs .pop() | |
if MSG .startswith( 'https://www.youtube.com' ): ## or ( MSG .find( 'http' ) > 0 ): | |
link = MSG[ MSG .find( 'http' ): ] | |
if link .find( ' ' ) > 0: ## strip off any remaining text after space | |
link = link[ :link .find( ' ' ) ] | |
req = requests .get( link ) | |
title = bs4 .BeautifulSoup( req .text ) .title | |
if title: | |
hexchat .command( 'action Webpage title: ' +title .text ) | |
def auto_op( word, word_eol, userdata ): | |
NICK = word[0] | |
CHAN = word[1] | |
IDENT = word[2] | |
if CHAN in CHANNELS: | |
## if NICK in OP: | |
## hexchat .command( 'op ' +NICK ) | |
## send_last3( NICK ) | |
if NICK in VOICE: | |
hexchat .command( 'voice ' +NICK ) | |
## send_last3( NICK ) | |
else: ## get everything before the @ symbol | |
ID, Location = IDENT .split( '@' ) | |
for O in OP: | |
if O .startswith( NICK ) or NICK .startswith( O ) or O .startswith( ID ) or ID .startswith( O ): | |
for L in Safe_OP_Locations: | |
if Location .endswith( L ): | |
hexchat .command( 'action Identified user ' +ID ) | |
hexchat .command( 'voice ' +NICK ) | |
## send_last3( NICK ) | |
for V in VOICE: | |
if V .startswith( NICK ) or NICK .startswith( V ) or V .startswith( ID ) or ID .startswith( V ): | |
hexchat .command( 'action Identified user ' +ID ) | |
hexchat .command( 'voice ' +NICK ) | |
## send_last3( NICK ) | |
if print_debug_msgs: | |
hexchat .prnt( debug_text .format( 'NICK', NICK ) ) | |
hexchat .prnt( debug_text .format( 'CHAN', CHAN ) ) | |
##========================================================= | |
## main loop | |
hexchat .hook_print( 'JOIN', auto_op ) | |
hexchat .hook_print( 'Your Message', store_three_and_print_urls ) ## from you | |
hexchat .hook_print( 'Channel Message', store_three_and_print_urls ) ## from others | |
hexchat .hook_print( 'Channel Msg Hilight', store_three_and_print_urls ) # directly to your name, in chat | |
hexchat .hook_print( 'Private Message to Dialog', store_three_and_print_urls ) # directly to you /msg | |
# hexchat .hook_print( 'Part', auto_op ) | |
# hexchat .hook_print( 'Part with Reason', auto_op ) | |
##========================================================= | |
## eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment