From fd7c4d44f5911a10df4c667a22cf95816c91077b Mon Sep 17 00:00:00 2001 From: Dylan Dizon Date: Sat, 3 Nov 2018 20:04:39 -0400 Subject: [PATCH] Prune incomplete, vestigial, and irrelevant code - Completely removed music cog for now - Halted Google Play Music integration - Removed "periodic_gpm" items from tasks file --- src/cogs/music.py | 57 -------------------------------------------- src/cogs/periodic.py | 8 ------- src/cogs/tools.py | 48 +------------------------------------ src/utils/utils.py | 3 +-- 4 files changed, 2 insertions(+), 114 deletions(-) delete mode 100644 src/cogs/music.py diff --git a/src/cogs/music.py b/src/cogs/music.py deleted file mode 100644 index b60d0f6..0000000 --- a/src/cogs/music.py +++ /dev/null @@ -1,57 +0,0 @@ -import asyncio -import json -from datetime import datetime as dt -from urllib import parse -import re -from pprint import pprint - -import discord as d -from discord import errors as err -from discord.ext import commands as cmds -from discord.ext.commands import errors as errext -# import gmusicapi as gpm -# import googleapiclient as gapic -# import apiclient as apic - -from misc import exceptions as exc -from misc import checks -from utils import utils as u - - -class Music: - - # def __init__(self, bot): - # self.bot = bot - # - # self.yt_service = apic.discovery.build('youtube', 'v3', developerKey=u.secrets['client_secrets']['client_secret']) - # - @cmds.group(aliases=['pl'], brief='(G) Play music', description='Play music from YouTube, Soundcloud, or Google Play Music') - async def play(self, ctx): - print(ctx.invoked_subcommand) - # - # @play.command(name='youtube', aliases=['you', 'tube', 'yt', 'y']) - # async def _play_youtube(self, ctx, *videos): - # try: - # if not videos: - # raise exc.MissingArgument - # - # vids = [] - # - # for video in videos: - # if 'http' in video and 'youtube' in video: - # vids.append(parse.parse_qs(parse.urlparse(video).query)['v'][0]) - # else: - # vids.append(video) - # - # print(vids) - # - # response = self.yt_service.videos().list(part='snippet', id=','.join(vids)).execute() - # pprint(response) - # - # except exc.MissingArgument: - # await ctx.send('**Invalid youtube url or ID**', delete_after=7) - # await ctx.message.add_reaction('\N{CROSS MARK}') - - @play.command(name='googleplaymusic', aliases=['googleplay', 'googlemusic', 'playmusic', 'play', 'gpm']) - async def _play_googleplaymusic(self, ctx, query): - pass diff --git a/src/cogs/periodic.py b/src/cogs/periodic.py index 1f36b88..40b328f 100644 --- a/src/cogs/periodic.py +++ b/src/cogs/periodic.py @@ -6,7 +6,6 @@ import discord as d from discord import errors as err from discord.ext import commands as cmds from discord.ext.commands import errors as errext -import gmusicapi as gpm from misc import exceptions as exc from misc import checks @@ -18,16 +17,9 @@ class Post: def __init__(self, bot): self.bot = bot - for task in u.tasks['periodic_gpm']: - self.bot.loop.create_task() - async def _check_posts(self, user, channel): pass @cmds.group(aliases=['update', 'up', 'u']) async def updates(self, ctx): pass - - @updates.command(name='googleplaymusic', aliases=['googlemusic', 'playmusic', 'music', 'gpm']) - async def _updates_googleplaymusic(self, ctx): - pass diff --git a/src/cogs/tools.py b/src/cogs/tools.py index 81704c5..2aedbe1 100644 --- a/src/cogs/tools.py +++ b/src/cogs/tools.py @@ -7,12 +7,7 @@ import traceback as tb import webbrowser import discord as d -import httplib2 -import requests_oauthlib as ro -from apiclient import http -from apiclient.discovery import build from discord.ext import commands as cmds -from oauth2client.client import flow_from_clientsecrets #from run import config from cogs import booru @@ -51,7 +46,7 @@ class Utils: await ctx.message.add_reaction('\N{TABLE TENNIS PADDLE AND BALL}') await ctx.send(ctx.author.mention + ' \N{TABLE TENNIS PADDLE AND BALL} `' + str(round(self.bot.latency * 1000)) + 'ms`', delete_after=5) - @cmds.command(aliases=['pre'], brief='List bot prefixes', description='Shows all used prefixes') + @cmds.command(aliases=['pre', 'prefixes'], brief='List bot prefixes', description='Shows all used prefixes') async def prefix(self, ctx): await ctx.send('**Prefix:** `{}`'.format('` or `'.join(u.settings['prefixes'][ctx.guild.id] if ctx.guild.id in u.settings['prefixes'] else u.config['prefix']))) @@ -80,44 +75,3 @@ class Utils: @send.command(name='user', aliases=['u', 'member', 'm']) async def send_user(self, ctx, user, *, message): await d.utils.get(self.bot.get_all_members(), id=int(user)).send(message) - - @cmds.command(aliases=['authenticateupload', 'authupload', 'authup', 'auth'], hidden=True) - async def authenticate_upload(self, ctx): - global youtube - flow = flow_from_clientsecrets('client_secrets.json', scope='https://www.googleapis.com/auth/youtube.upload', - login_hint='botmyned@gmail.com', redirect_uri='urn:ietf:wg:oauth:2.0:oob') - flow.params['access_type'] = 'offline' - webbrowser.open_new_tab(flow.step1_get_authorize_url()) - credentials = flow.step2_exchange(input('Authorization code: ')) - youtube = build('youtube', 'v3', http=credentials.authorize(http.build_http())) - print('Service built.') - - @cmds.command(aliases=['up', 'u', 'vid', 'v'], hidden=True) - @cmds.has_permissions(administrator=True) - async def upload(self, ctx): - global youtube - attachments = ctx.message.attachments - try: - if not attachments: - raise exc.MissingAttachment - if len(attachments) > 1: - raise exc.TooManyAttachments(len(attachments)) - mime = mimetypes.guess_type(attachments[0].filename)[0] - if 'video/' in mime: - with tempfile.NamedTemporaryFile() as temp: - await attachments[0].save(temp) - else: - raise exc.InvalidVideoFile(mime) - print('https://www.youtube.com/watch?v=' + youtube.videos().insert(part='snippet', - body={'categoryId': '24', 'title': 'Test'}, media_body=http.MediaFileUpload(temp.name, chunksize=-1))) - except exc.InvalidVideoFile as e: - await ctx.send('`' + str(e) + '` **invalid video type**', delete_after=7) - except exc.TooManyAttachments as e: - await ctx.send('`' + str(e) + '` **too many attachments.** Only one attachment is permitted to upload.', delete_after=7) - except exc.MissingAttachment: - await ctx.send('**Missing attachment**', delete_after=7) - - @upload.error - async def upload_error(self, ctx, error): - pass -# http. diff --git a/src/utils/utils.py b/src/utils/utils.py index 64bc89d..73bb1ee 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -6,7 +6,6 @@ import subprocess from contextlib import suppress from fractions import gcd import math -import gmusicapi as gpm import aiohttp import discord as d @@ -82,7 +81,7 @@ def dump(obj, filename, *, json=False): settings = setdefault('misc/settings.pkl', default={'del_ctx': [], 'del_resp': [], 'prefixes': {}}) -tasks = setdefault('cogs/tasks.pkl', default={'auto_del': [], 'auto_hrt': [], 'auto_rev': [], 'periodic_gpm': []}) +tasks = setdefault('cogs/tasks.pkl', default={'auto_del': [], 'auto_hrt': [], 'auto_rev': []}) temp = setdefault('temp/temp.pkl', default={'startup': ()}) secrets = setdefault('secrets.json', default={'client_secrets': {'client_id': '', 'client_secret': ''}}, json=True)