Commit 69c3d0ec authored by Rob Nelson's avatar Rob Nelson
Browse files

Automated updated for BBD

parent 87889ce5
import os, stat, re, json, pathlib, tempfile, shutil, pygit2
import os, stat, re, json, pathlib, tempfile, shutil, pygit2, requests
from typing import Dict
from buildtools import os_utils, log
from discordjail.addons.framework import Addon, Addons
......@@ -16,12 +16,14 @@ REG_VERSION = re.compile(r'[0-9]+\.[0-9]+\.[0-9]+')
BBD_PLUGIN_REPO = 'https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/PluginRepo/PluginRepo.plugin.js'
BBD_THEME_REPO = 'https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ThemeRepo/ThemeRepo.plugin.js'
BBD_BDFDB_REPO = 'https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Library/0BDFDB.plugin.js'
ZPL_URI = 'https://raw.githubusercontent.com/rauenzi/BDPluginLibrary/master/release/0PluginLibrary.plugin.js'
ENABLE_BY_DEFAULT = [
'PluginRepo',
'ThemeRepo'
'ThemeRepo',
'BDFDB',
]
class BBDPlugin(object):
......@@ -32,16 +34,43 @@ class BBDPlugin(object):
@classmethod
def CreateFromFile(cls, filename: str) -> 'BDDPlugin':
basename = os.path.basename(filename)
pluginid = basename.replace('.plugin.js', '')
with open(filename, 'r') as f:
plug = None
for line in f:
line=line.strip()
if line.startswith('//META{'):
meta = json.loads(line[6:line.find('}')])
if 'name' in meta and 'source' in meta:
if line.startswith('//META'):
print(line[6:line.find('}')+1].strip())
meta = json.loads(line[6:line.find('}')+1].strip())
if 'name' in meta:
plug = cls()
plug.id = plug.name = meta['name']
plug.url = meta['source']
plug.id = pluginid
plug.name = meta['name']
plug.url = meta.get('source', None)
if plug.url is None:
plug.url = f'https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/{plug.name}/{plug.id}.plugin.js'
req = requests.head(plug.url)
if req.status_code == 404:
log.warning(f'Received HTTP {req.status_code} from {plug.url!r}')
plug.url = None
return plug
if '@name ' in line:
i = line.find('@name ') + 6
if plug is None:
plug = cls()
plug.id = pluginid
plug.id = plug.name = line[i:].strip()
if '@source ' in line:
i = line.find('@source ') + 8
assert plug is not None
plug.url = line[i:].strip()
if plug is not None:
assert plug.id is not None
assert plug.name is not None
assert plug.url is not None
return plug
log.error('File %r has no //META{ tag nor @name!', filename)
return None
def deserialize(self, key: str, data: dict) -> None:
......@@ -50,7 +79,8 @@ class BBDPlugin(object):
self.url = data['url']
def install(self, bbd: 'BandagedBetterDiscordAddon') -> None:
download_file_to(self.url, os.path.join(bbd.plugins_dir, f'{self.id}.plugin.js'))
if self.url is not None:
download_file_to(self.url, os.path.join(bbd.plugins_dir, f'{self.id}.plugin.js'))
class BBDTheme(BBDPlugin):
@classmethod
......@@ -93,6 +123,7 @@ class BandagedBetterDiscordAddon(Addon):
self.plugins['PluginRepo'] = BBDPlugin('PluginRepo', BBD_PLUGIN_REPO)
self.plugins['ThemeRepo'] = BBDPlugin('ThemeRepo', BBD_THEME_REPO)
self.plugins['0PluginLibrary'] = BBDPlugin('0PluginLibrary', ZPL_URI)
self.plugins['0BDFDB'] = BBDPlugin('0BDFDB', BBD_BDFDB_REPO)
def deserialize(self, data: dict) -> None:
super().deserialize(data)
......@@ -346,6 +377,14 @@ class BandagedBetterDiscordAddon(Addon):
curbase=curbase[key]
bdstorage['settings']['stable']['plugins'][plid] = True
plugins = {}
for filename in os_utils.get_file_list(self.plugins_dir):
if filename.endswith('.plugin.js'):
plugin = BBDPlugin.CreateFromFile(os.path.join(self.plugins_dir, filename))
if plugin.name in bdstorage['settings']['stable']['plugins'].keys() and bdstorage['settings']['stable']['plugins'][plugin.name]:
self.plugins[plugin.name] = plugin
log.info('Found plugin %s and enabled it.', plugin.id)
for plugin in self.plugins.values():
plugin.install(self)
......
pybuildtools==0.3.6
isort==5.6.4
mypy==0.790
# Generated by vnm.
version: 3
packages:
pybuildtools:
frozen-at: 0.3.6
dev-packages:
isort:
frozen-at: 5.6.4
mypy:
frozen-at: '0.790'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment