Browse Source

Renamed scripts, and made weechat script 2.7 compliant

master
Teknikode 2 years ago
parent
commit
91edc1d130
2 changed files with 39 additions and 26 deletions
  1. 0
    0
      Hexchat/teknik.py
  2. 39
    26
      Weechat/teknik.py

Hexchat/teknik_upload.py → Hexchat/teknik.py View File


Weechat/teknik_upload.py → Weechat/teknik.py View File

@@ -1,39 +1,36 @@
#!/usr/bin/python
import_success = True

import tkinter as tk
from tkinter.filedialog import askopenfilename
import os
import Tkinter as tk
import tkFileDialog

try:
import weechat
except ImportError:
print('This script must be run under WeeChat.')
print('Get WeeChat now at: http://www.weechat.org/')
import_ok = False
import_success = False

# Requires Install
try:
from teknik import uploads as teknik
except ImportError as e:
print('Missing package(s) for %s: %s' % ('Teknik Upload', e))
import_ok = False
import_success = False

# Weechat Registration
weechat.register("Teknik Upload", "Uncled1023", "1.0.0", "BSDv3", "Uploads files to the Teknik Services", "", "")
weechat.register("Teknik_Upload", "Uncled1023", "1.0.0", "BSDv3", "Uploads files to the Teknik Services", "", "")

def teknik_prompt():
def teknik_prompt(file):
# Get current config values
apiUrl = weechat.config_string(weechat.config_get('plugins.var.python.teknik.api_url'))
apiUsername = weechat.config_string(weechat.config_get('plugins.var.python.teknik.username'))
apiToken = weechat.config_string(weechat.config_get('plugins.var.python.teknik.token'))
# Prompt for a file
root = tk.Tk()
root.withdraw()
file_path = askopenfilename()
if file_path != '':
if file is not None and os.path.exists(file):
# Try to upload the file
results = teknik.UploadFile(apiUrl, file_path, apiUsername, apiToken)
results = teknik.UploadFile(apiUrl, file, apiUsername, apiToken)
# Either print the result to the input box, or write the error message to the window
if 'error' in results:
@@ -56,26 +53,41 @@ def teknik_set_username(username):
def teknik_command(data, buffer, args):
args = args.strip()
if args == "":
teknik_prompt()
print("Error: You must specify a command")
else:
argv = args.split(" ")
command = argv[0].lower()
if command == 'username':
if len(argv) < 2:
print("Error: You must specify a username")
else:
teknik_set_username(argv[1])
elif command == 'token':
# Upload a File
if command == 'upload':
if len(argv) < 2:
print("Error: You must specify an auth token")
print("Error: You must specify a file")
else:
teknik_set_token(argv[1])
elif command == 'url':
teknik_prompt(argv[1])
# Set a config option
elif command == 'set':
if len(argv) < 2:
print("Error: You must specify an api url")
print("Error: You must specify the option to set")
else:
teknik_set_url(argv[1])
option = argv[1].lower()
if option == 'username':
if len(argv) < 3:
print("Error: You must specify a username")
else:
teknik_set_username(argv[2])
elif option == 'token':
if len(argv) < 3:
print("Error: You must specify an auth token")
else:
teknik_set_token(argv[2])
elif option == 'url':
if len(argv) < 3:
print("Error: You must specify an api url")
else:
teknik_set_url(argv[2])
else:
print("Error: Unrecognized Option")
else:
print("Error: Unrecognized Command")
@@ -83,7 +95,8 @@ def teknik_command(data, buffer, args):

if __name__ == "__main__" and import_success:
hook = weechat.hook_command("teknik", "Allows uploading of a file to Teknik and sharing the url directly to the chat.",
"[username|token|url <username|auth_token|api_url>]",
"[upload <file>] | [set username|token|url <username|auth_token|api_url>]",
' file: The file you want to upload'
' username: The username for your Teknik account'
' auth_token: The authentication token for your Teknik Account'
' api_url: The URL for the Upload API',

Loading…
Cancel
Save