Просмотр исходного кода

Added Initial Hexchat addon

master
Teknikode 2 лет назад
Родитель
Сommit
ad3575fe5e
7 измененных файлов: 102 добавлений и 0 удалений
  1. 0
    0
      Hexchat/README.md
  2. 102
    0
      Hexchat/teknik_upload.py
  3. 0
    0
      Paste/paste.sh
  4. 0
    0
      Upload/teknik.sh
  5. 0
    0
      Upload/upload.sh
  6. 0
    0
      license.md
  7. 0
    0
      readme.md

+ 0
- 0
Hexchat/README.md Просмотреть файл


+ 102
- 0
Hexchat/teknik_upload.py Просмотреть файл

@@ -0,0 +1,102 @@
__module_name__ = "Teknik Upload"
__module_version__ = "1.0"
__module_description__ = "Upload files to Teknik"

import hexchat
import base64
import json
import tkinter as tk
from tkinter.filedialog import askopenfilename

# Requires Install
import requests

defaultUrl = 'https://api.teknik.io/v1/Upload'
defaultUsername = ''
defaultToken = ''

def teknik_prompt():
# Get current config values
apiUrl = defaultUrl
apiUsername = defaultUsername
apiToken = defaultToken
cfgUrl = hexchat.get_pluginpref('teknik_url')
if cfgUrl is not None:
apiUrl = cfgUrl
cfgUsername = hexchat.get_pluginpref('teknik_username')
if cfgUsername is not None:
apiUsername = cfgUsername
cfgToken = hexchat.get_pluginpref('teknik_auth_token')
if cfgToken is not None:
apiToken = cfgToken
# Prompt for a file
root = tk.Tk()
root.withdraw()
file_path = askopenfilename()
if file_path != '':
# Create the request
files = {'file': open(file_path, "rb")}
# Create a header if they have added auth info
headers = {}
if apiUsername != '' and apiToken != '':
encAuth = base64.b64encode(apiUsername + ':' + apiToken)
headers = {'Authorization': 'Basic ' + encAuth}
r = requests.post(apiUrl, files=files, headers=headers)
jObj = json.loads(r.text)
# Either print the result to the input box, or write the error message to the window
if 'error' in jObj:
hexchat.prnt('Error: ' + jObj['error']['message'])
elif 'result' in jObj:
hexchat.command("settext " + jObj['result']['url'])
else:
hexchat.prnt('Unknown Error')

def teknik_set_url(url):
hexchat.set_pluginpref('teknik_url', url)
def teknik_set_token(token):
hexchat.set_pluginpref('teknik_auth_token', token)

def teknik_set_username(username):
hexchat.set_pluginpref('teknik_username', username)
def teknik_command(word, word_eol, userdata):
if len(word) < 2:
teknik_prompt()
else:
command = word[1].lower()
if command == 'username':
if len(word) < 3:
hexchat.prnt("Error: You must specify a username")
else:
teknik_set_username(word[2])
elif command == 'token':
if len(word) < 3:
hexchat.prnt("Error: You must specify an auth token")
else:
teknik_set_token(word[2])
elif command == 'url':
if len(word) < 3:
hexchat.prnt("Error: You must specify an api url")
else:
teknik_set_url(word[2])
else:
hexchat.prnt("Error: Unrecognized Command")
return hexchat.EAT_ALL

hexchat.hook_command("TEKNIK", teknik_command, help="""Allows uploading of a file to Teknik and sharing the url directly to the chat.

Usage: TEKNIK
TEKNIK username <username>
TEKNIK token <auth_token>
TEKNIK url <api_url>""")

+ 0
- 0
Paste/paste.sh Просмотреть файл


+ 0
- 0
Upload/teknik.sh Просмотреть файл


+ 0
- 0
Upload/upload.sh Просмотреть файл


+ 0
- 0
license.md Просмотреть файл



Загрузка…
Отмена
Сохранить