Browse Source

Added Initial Hexchat addon

Teknikode 1 year ago
parent
commit
ad3575fe5e
7 changed files with 102 additions and 0 deletions
  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 View File


+ 102
- 0
Hexchat/teknik_upload.py View File

@@ -0,0 +1,102 @@
1
+__module_name__ = "Teknik Upload"
2
+__module_version__ = "1.0"
3
+__module_description__ = "Upload files to Teknik"
4
+
5
+import hexchat
6
+import base64
7
+import json
8
+import tkinter as tk
9
+from tkinter.filedialog import askopenfilename
10
+
11
+# Requires Install
12
+import requests
13
+
14
+defaultUrl = 'https://api.teknik.io/v1/Upload'
15
+defaultUsername = ''
16
+defaultToken = ''
17
+
18
+def teknik_prompt():
19
+    # Get current config values
20
+    apiUrl = defaultUrl
21
+    apiUsername = defaultUsername
22
+    apiToken = defaultToken
23
+    
24
+    cfgUrl = hexchat.get_pluginpref('teknik_url')
25
+    if cfgUrl is not None:
26
+      apiUrl = cfgUrl
27
+    
28
+    cfgUsername = hexchat.get_pluginpref('teknik_username')
29
+    if cfgUsername is not None:
30
+      apiUsername = cfgUsername
31
+    
32
+    cfgToken = hexchat.get_pluginpref('teknik_auth_token')
33
+    if cfgToken is not None:
34
+      apiToken = cfgToken
35
+    
36
+    # Prompt for a file
37
+    root = tk.Tk()
38
+    root.withdraw()
39
+    file_path = askopenfilename()
40
+    
41
+    if file_path != '':
42
+      # Create the request
43
+      files = {'file': open(file_path, "rb")}
44
+      
45
+      # Create a header if they have added auth info
46
+      headers = {}
47
+      if apiUsername != '' and apiToken != '':
48
+        encAuth = base64.b64encode(apiUsername + ':' + apiToken)
49
+        headers = {'Authorization': 'Basic ' + encAuth}
50
+      
51
+      r = requests.post(apiUrl, files=files, headers=headers)
52
+      jObj = json.loads(r.text)
53
+      
54
+      # Either print the result to the input box, or write the error message to the window
55
+      if 'error' in jObj:
56
+        hexchat.prnt('Error: ' + jObj['error']['message'])
57
+      elif 'result' in jObj:      
58
+        hexchat.command("settext " + jObj['result']['url'])
59
+      else:
60
+        hexchat.prnt('Unknown Error')
61
+
62
+def teknik_set_url(url):
63
+  hexchat.set_pluginpref('teknik_url', url)
64
+  
65
+def teknik_set_token(token):
66
+  hexchat.set_pluginpref('teknik_auth_token', token)
67
+
68
+def teknik_set_username(username):
69
+  hexchat.set_pluginpref('teknik_username', username)
70
+      
71
+def teknik_command(word, word_eol, userdata):
72
+  if len(word) < 2:
73
+    teknik_prompt()
74
+  else:
75
+    command = word[1].lower()
76
+    
77
+    if command == 'username':
78
+      if len(word) < 3:
79
+        hexchat.prnt("Error: You must specify a username")
80
+      else:
81
+        teknik_set_username(word[2])
82
+    elif command == 'token':
83
+      if len(word) < 3:
84
+        hexchat.prnt("Error: You must specify an auth token")
85
+      else:
86
+        teknik_set_token(word[2])
87
+    elif command == 'url':
88
+      if len(word) < 3:
89
+        hexchat.prnt("Error: You must specify an api url")
90
+      else:
91
+        teknik_set_url(word[2])
92
+    else:
93
+      hexchat.prnt("Error: Unrecognized Command")
94
+  
95
+  return hexchat.EAT_ALL
96
+
97
+hexchat.hook_command("TEKNIK", teknik_command, help="""Allows uploading of a file to Teknik and sharing the url directly to the chat.
98
+
99
+Usage: TEKNIK
100
+       TEKNIK username <username>
101
+       TEKNIK token <auth_token>
102
+       TEKNIK url <api_url>""")

+ 0
- 0
Paste/paste.sh View File


+ 0
- 0
Upload/teknik.sh View File


+ 0
- 0
Upload/upload.sh View File


+ 0
- 0
license.md View File


+ 0
- 0
readme.md View File


Loading…
Cancel
Save