-
-
Save felmey/8b72a58821871573f75ea5a78084db17 to your computer and use it in GitHub Desktop.
#bitcoin-otc HexChat Plugin (updated for Python 3)
This file contains hidden or 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
import hexchat | |
from subprocess import Popen, PIPE | |
import urllib | |
import re | |
from urllib.request import urlopen | |
# HexChat #bitcoin-otc IRC Plugin | |
# Copyright (C) 2015 Zeke Sonxx <github.com/zekesonxx> | |
# Copyright (C) 2017 Robert Felmey <https://github.com/felmey> | |
# | |
#Permission is hereby granted, free of charge, to any person obtaining a copy | |
#of this software and associated documentation files (the "Software"), to deal | |
#in the Software without restriction, including without limitation the rights | |
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
#copies of the Software, and to permit persons to whom the Software is | |
#furnished to do so, subject to the following conditions: | |
# | |
#The above copyright notice and this permission notice shall be included in all | |
#copies or substantial portions of the Software. | |
# | |
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
#SOFTWARE. | |
# License: MIT - choosealicense.com/licenses/mit/ | |
# ### Features ### | |
# - Adds the /ident command | |
# (just a shortcut for getting gribble ident) | |
# - Adds the /otcauth command | |
# Kicks off a gribble login | |
# Based on https://github.com/TingPing/plugins/blob/master/HexChat/twitch.py | |
__module_name__ = 'bitcoin-otc' | |
__module_author__ = 'Zeke Sonxx' | |
__module_version__ = '0.0.1' | |
__module_description__ = 'Utilites for #bitcoin-otc in HexChat' | |
identhandle = None | |
otcauthhandle = None | |
otphandle = None | |
def otcOnly(func): | |
"""Only execute in the #bitcoin-otc channel""" | |
def if_ec(*args, **kwargs): | |
channel = hexchat.get_info('channel') | |
if channel and (channel == '#bitcoin-otc'): | |
return func(*args, **kwargs) | |
else: | |
return hexchat.EAT_NONE | |
return if_ec | |
def ident_cb(word, word_eol, userdata): | |
"""Passthrough command for /msg gribble ident <user>""" | |
if len(word) < 2: | |
hexchat.prnt("/ident <user> Gets the user's current otc identity") | |
return hexchat.EAT_ALL | |
hexchat.command("query gribble ident "+word[1]) | |
return hexchat.EAT_ALL | |
def otcauth_cb(word, word_eol, userdata): | |
"""Passthrough command for /msg gribble eauth <user>""" | |
if len(word) < 2: | |
hexchat.prnt("/otcauth <username> GPG authenticate with gribble") | |
return hexchat.EAT_ALL | |
otcuser = word[1] | |
hexchat.command("msg gribble gpg eauth "+otcuser) | |
return hexchat.EAT_ALL | |
def otp_cb(word, word_eol, userdata): | |
"""Catches a gribble gpg challenge and completes it""" | |
if hexchat.nickcmp(word[0][:9], ':gribble!') != 0: | |
# not gribble | |
return hexchat.EAT_NONE | |
results = re.search("Get your encrypted OTP from (http://[^$ ]+)", | |
word_eol[3]) | |
if results is None or len(results.group(1)) == 0: | |
# Not a challenge message | |
return hexchat.EAT_NONE | |
otpurl = results.group(1) | |
challenge = urlopen(otpurl).read() | |
p = Popen(["gpg2", "--decrypt"], stdin=PIPE, stdout=PIPE, stderr=PIPE) | |
stdout, stderr = p.communicate(challenge) | |
otp = hexchat.strip(stdout.strip()) | |
hexchat.command("msg gribble everify "+otp+" ") | |
return hexchat.EAT_ALL | |
def hexchatisapileofshit(userdata): | |
# So that you have a higher chance of not crashing when reloading. | |
# You'll still probably crash. It's hexchat's fault. | |
global identhandle | |
global otcauthhandle | |
global otphandle | |
global finishauthhandle | |
if identhandle is not None: | |
hexchat.unhook(identhandle) | |
identhandle = None | |
if otcauthhandle is not None: | |
hexchat.unhook(otcauthhandle) | |
otcauthhandle = None | |
if otphandle is not None: | |
hexchat.unhook(otphandle) | |
otphandle = None | |
pass | |
identhandle = hexchat.hook_command("ident", ident_cb) | |
otcauthhandle = hexchat.hook_command("otcauth", otcauth_cb) | |
otphandle = hexchat.hook_server("PRIVMSG", otp_cb) | |
hexchat.hook_unload(hexchatisapileofshit) |
This file contains hidden or 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
-----BEGIN PGP SIGNATURE----- | |
iQEzBAABCAAdFiEEbGrjGhQqbg2C2Zan/zaxRn2hqqAFAlo5/aEACgkQ/zaxRn2h | |
qqD0mgf/fhDJPVkB6jzkiTFwRPmhKyKYektNmwMLlxmwFzITq+P7ExThdp4j6s6k | |
o1UgOBnNoD83HzodZC2dmOYJD1VB1LPAZznh7YffhDizhjQqgysk17JgjVCVWLuq | |
qsRYGFvNMBzxEKXsL9aw4Cf1ZaMpk0WqGUaGzPSoSuF0Jh2OvmHTLzapjiDY0q2g | |
Cbq89Q6ZjGq6EYkurGKwOM8nQn7G2/Qpov6+3Gy12jw2vDiftd9iN7REwCkkThIs | |
5L+ycPEyRxhoWuMDfv4tX3U+4gRJHNlNQzRjsWz0LLHjEQOq7WGg2M3B/dEXgXOr | |
/D16DXe0bRfEp8+3nlNIi5IY/4tJOQ== | |
=/kBO | |
-----END PGP SIGNATURE----- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment