71 lines
1.8 KiB
Python
71 lines
1.8 KiB
Python
#-*- coding: utf-8 -*-
|
||
# Copyright (c) 2013 Anton Vilhelm Ãsgeirsson <anton@antonvilhelm.is>
|
||
#
|
||
# Everyone is permitted to copy and distribute verbatim or modified
|
||
# copies of this license document, and changing it is allowed as long
|
||
# as the name is changed.
|
||
#
|
||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||
#
|
||
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
||
|
||
# Greentext:
|
||
# ----------
|
||
# Modifies any messages starting with '>' to display green text, similar to
|
||
# the way popular imageboards do.
|
||
|
||
import weechat as w
|
||
import re
|
||
import requests
|
||
|
||
# Registstration variables.
|
||
SCRIPT_NAME = "autottm"
|
||
SCRIPT_AUTHOR = "God"
|
||
SCRIPT_VERSION = "0.1"
|
||
SCRIPT_LICENSE = "WTFPL"
|
||
SCRIPT_DESC = "Modify messages starting with 'https://cdn.discordapp.com' to display better link."
|
||
|
||
# Registration function.
|
||
w.register(
|
||
SCRIPT_NAME,
|
||
SCRIPT_AUTHOR,
|
||
SCRIPT_VERSION,
|
||
SCRIPT_LICENSE,
|
||
SCRIPT_DESC,
|
||
"",""
|
||
)
|
||
|
||
# Greentext callback function.
|
||
def greentext_cb(data, modifier, modifier_data, string):
|
||
try:
|
||
nick, msg = string.split('\t')
|
||
except ValueError as e: #Get rid of those python error messages.
|
||
return string
|
||
try:
|
||
discordindex = msg.index('https://')
|
||
except:
|
||
return string
|
||
wackindex = len(msg) -1
|
||
if msg.find('.png') > -1:
|
||
wackindex = msg.index('.png')
|
||
elif msg.find('.jpg') > -1:
|
||
wackindex = msg.index('.jpg')
|
||
else:
|
||
return string
|
||
msg = msg[discordindex:wackindex+4]
|
||
|
||
#print(discordindex)
|
||
#print(msg[discordindex:])
|
||
|
||
data = {
|
||
'url': msg
|
||
}
|
||
r = requests.post(url = 'https://ttm.sh', data = data)
|
||
print(r.text)
|
||
return "%s\t%s%s" % (nick, w.color('green'), r.text)
|
||
#return r.text
|
||
|
||
|
||
|
||
w.hook_modifier("weechat_print", "greentext_cb", "") |