示例#1
0
def main():
    """
    The main entry point.

    Invoke using `python -m discobot`.
    """
    parser = argparse.ArgumentParser(
        prog='discobot', description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument(
        'config', nargs='?', type=argparse.FileType('r'),
        default='config.yaml', help='configuration file to use')
    args = parser.parse_args()

    config = yaml.load(args.config.read())
    args.config.close()

    kwargs = config.get('log', {}).copy()
    level = getattr(logging, kwargs.pop('level', 'info').upper(), logging.INFO)
    logging.basicConfig(level=level, **kwargs)

    if not opus.is_loaded():
        opus.load_opus(config['opus_library_path'])

    bot.configure(config)
    bot.run(config['bot']['token'])
示例#2
0
 def __init__(self, bot: Yasen):
     self.bot = bot
     self.music_managers = {}
     if not opus.is_loaded():
         raise ValueError('libopus is not loaded, please install the'
                          'library through your package manager or add'
                          'it to your PATH.')
示例#3
0
    def __init__(self, key_store_path: str):
        if not opus.is_loaded():
            opus.load_opus()

        keys = []
        with open(key_store_path, 'r') as key_file:
            keys = key_file.readlines()
            for idx, key in enumerate(keys):
                keys[idx] = key.split(":")[1].strip()

        self.bot_token = keys[0]
        self.bot_id = keys[1]

        self.song_list = []
        self.stop = False
        self.is_playing = False
        self.player = None

        self.admin_roles = ["Butcher of Reports", "Admin"]
        self.image_store_path = "Other_Images"
        self.images = Images(self.image_store_path)

        self.image_processing = ImageProcess()
        self.reddit = RedditBot(id=keys[2],
                                secret=keys[3],
                                user=keys[4],
                                password=keys[5],
                                agent=keys[6])
示例#4
0
def load_opus_lib(opus_libs=OPUS_LIBS):
    if platform.system() == 'Linux':
        print("Linux detected")

        try:
            shutil.copy("./.apt/lib/x86_64-linux-gnu/libusb-1.0.so.0",
                        "./.apt/usr/lib/x86_64-linux-gnu/libusb-1.0.so.0")
            shutil.copy(
                "./.apt/usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-11.1.so",
                "./.apt/usr/lib/x86_64-linux-gnu/libpulsecommon-11.1.so")
            shutil.copy("./.apt/lib/x86_64-linux-gnu/libslang.so.2",
                        "./.apt/usr/lib/x86_64-linux-gnu/libslang.so.2")
        except FileNotFoundError:
            pass

        for opus_lib in OPUS_LIBS_LINUX:
            try:
                opus.load_opus(opus_lib)
                print("Tried %s" % opus_lib)
                return
            except OSError:
                raise RuntimeError('Could not load an opus lib. Tried %s' %
                                   (', '.join(opus_libs)))

    if opus.is_loaded():
        print('Opus loaded')
        return True
示例#5
0
def test_has_voice():
    from discord.voice_client import has_nacl
    from discord.opus import is_loaded, Encoder

    Encoder()  # Ensure opus gets loaded

    assert has_nacl
    assert is_loaded()
示例#6
0
def load_opus_lib(opus_libs=OPUS_LIBS):
    if platform.system() == 'Windows': return True
    if opus.is_loaded(): return True
    for opus_lib in opus_libs:
        try:
            opus.load_opus(opus_lib)
            return True
        except OSError:
            raise RuntimeError(f"Could not load an opus lib ({opus_lib}). Tried {', '.join(opus_libs)}")
示例#7
0
文件: music.py 项目: dezertuk/foxxybt
 async def join(self, ctx):
     opus_path = find_library('opus')
     discord.opus.load_opus(opus_path)
     if not opus.is_loaded():
         print('Opus was not loaded')
     else:
         channel = ctx.message.author.voice.voice_channel
         await self.client.join_voice_channel(channel)
         print("Bot joined the voice channel")
示例#8
0
def load_opus_lib(opus_libs=OPUS_LIBS):
    if opus.is_loaded():
        return True
    for opus_lib in opus_libs:
        try:
            opus.load_opus(opus_lib)
            return
        except OSError:
            pass
    raise RuntimeError('Could not load an opus lib. Tried %s' % (', '.join(opus_libs)))
示例#9
0
def load_opus_lib():
    if opus.is_loaded():
        return True

    for opus_lib in OPUS_LIBS:
        try:
            opus.load_opus(opus_lib)
            return
        except OSError:
            pass
示例#10
0
def load_opus_lib():
    if opus.is_loaded():
        return

    try:
        opus._load_default()
        return
    except OSError:
        print("Cannot load opus library")
        pass
示例#11
0
def load_opus_lib():
    if opus.is_loaded():
        return

    try:
        opus._load_default()
        return
    except OSError:
        pass

    raise RuntimeError('Could not load an opus lib.')
示例#12
0
文件: voice.py 项目: wquist/DECbot
	async def on_ready(self):
		""" Retrieve sibling cogs and perform setup before the bot runs.

		At this point, libopus should have been loaded if it was detected by
		Discord. Otherwise, the path will be grabbed from the config file (it
		must be defined at this point).

		:raises RuntimeError: If libopus could still not be loaded, or no path
		                      was defined in the config, an error is raised.
		"""
		self.send_message = self.bot.get_cog('Text').send_message
		if opus.is_loaded():
			return

		path = config.get('opus')
		if path:
			opus.load_opus(path)

		if not opus.is_loaded():
			raise RuntimeError('Could not load libopus.')
示例#13
0
def load_opus_lib(opus_libs=OPUS_LIBS):
    if opus.is_loaded():
        return True
    for opus_lib in opus_libs:
        try:
            opus.load_opus(opus_lib)
            return
        except OSError:
            pass
    raise RuntimeError("OPUS 라이브러리를 로드하는데 실패했어용. 이것들을 시도해봤어용: {}".format(
        ", ".join(opus_libs)))
示例#14
0
def load_opus_lib(opus_libs=OPUS_LIBS):
    if opus.is_loaded():
        return True
    for opus_lib in opus_libs:
        try:
            opus.load_opus(opus_lib)
            log.debug("Loaded opus lib \"{}\"".format(opus_lib))
            return
        except OSError:
            pass
    log.critical("Could not load an opus lib. Tried {}".format(", ".join(opus_libs)))
    os._exit(1)
示例#15
0
 async def on_ready(self):
     print(f"{colors.YELLOW}BOT STARTED!{colors.END}")
     print("--" * 20)
     print(f"{colors.CYAN}Name{colors.END}: {colors.YELLOW}{self.bot.user.name}{colors.END}")
     print(f"{colors.CYAN}ID{colors.END}: {colors.YELLOW}{self.bot.user.id}{colors.END}")
     print(f"{colors.CYAN}Guilds{colors.END}: {colors.YELLOW}{len(self.bot.guilds)}{colors.END}")
     print("--" * 20)
     print(f"{colors.CYAN}Invite{colors.END}: https://www.discordapp.com/oauth2/authorize?client_id={self.bot.user.id}&scope=bot&permissions=-1")
     print("--" * 20)
     if opus.is_loaded():
         print(f"{colors.CYAN}Opus is loaded and ready!{colors.END}")
         print("--" * 20)
示例#16
0
def load_opus_lib(opus_libs=OPUS_LIBS):
    if opus.is_loaded():
        return True
    for opus_lib in opus_libs:
        try:
            opus.load_opus(opus_lib)
            log.debug("Loaded opus lib \"{}\"".format(opus_lib))
            return
        except OSError:
            pass
    log.critical("Could not load an opus lib. Tried {}".format(", ".join(opus_libs)))
    os._exit(1)
示例#17
0
def load_opus_lib(opus_libs=OPUS_LIBS):
    if opus.is_loaded():
        return True

    for opus_lib in opus_libs:
            try:
                opus.load_opus(opus_lib)
                return
            except OSError:
                pass

    raise RuntimeError('Could not load an opus lib. Tried %s' %(', '.join(opus_libs)))
示例#18
0
def load_opus_lib(opus_libs=OPUS_LIBS):
    if opus.is_loaded():
        return True

    for opus_lib in opus_libs:
        try:
            opus.load_opus(opus_lib)
            return
        except OSError:
            pass

    raise RuntimeError('opus libを読み込めませんでした。試した%s' % (', '.join(opus_libs)))
示例#19
0
def load_opus_lib(opus_libs=OPUS_LIBS):
    if opus.is_loaded():
        return True

    for opus_lib in opus_libs:
        try:
            opus.load_opus(opus_lib)
            return True
        except OSError:
            pass

    raise RuntimeError("Could not load an opus lib. Tried {0}".format(
        ", ".join(opus_libs)))
示例#20
0
def load_opus_lib(opus_libs=OPUS_LIBS):
    if opus.is_loaded():
        return True

    for opus_lib in opus_libs:
        try:
            opus.load_opus(opus_lib)
            return
        except OSError:
            pass

    raise RuntimeError('No se pudo cargar una librería de opus. Intentó %s' %
                       (', '.join(opus_libs)))
示例#21
0
def load_opus_lib(opus_libs=OPUS_LIBS):
    if opus.is_loaded():
        print("libopus loaded")
        return True

    for opus_lib in opus_libs:
        try:
            opus.load_opus(opus_lib)
            return
        except OSError:
            pass
        
    raise RuntimeError("Couldn't load opuslib. Tried %s" % (', '.join(opus_libs)))
示例#22
0
    async def make_player(self, voice, item):
        location = item['url']
        if item['type'] == 0:
            file_location = self.download_yt_data(location)
        elif item['type'] == 1:
            file_location = await self.download_sc_data(location)
        else:
            file_location = location

        if not opus.is_loaded():
            print("opus is not loaded")
        else:
            print("opus is loaded")

        source = discord.FFmpegPCMAudio(file_location, executable='ffmpeg')
        voice.play(source)
示例#23
0
    def __init__(self, sparcli):
        self.sparcli = sparcli
        self.voice = {}

        # Start OPUS if not loaded
        if not opus.is_loaded():
            opus.load_opus(find_library('opus'))

        # Load what VCs it's already in
        for i in self.sparcli.servers:

            # Set up a nice dictionary for storage of information
            voiceClientInServer = self.sparcli.voice_client_in(i)
            self.voice[i] = ServerVoice(bot=self.sparcli,
                                        server=i,
                                        voiceClient=voiceClientInServer)
示例#24
0
def load_opus_lib(opus_libs=OPUS_LIBS):
    if opus.is_loaded():
        print("Opus Already Loaded")
        return True

    for opus_lib in opus_libs:
        try:
            opus.load_opus(opus_lib)
            print("Opus loaded with lib {}".format(opus_lib))
            return
        except OSError:
            print("OS ERROR!")
            return

    raise RuntimeError('Could not load an opus lib. Tried %s' %
                       (', '.join(opus_libs)))
示例#25
0
async def load_opus_lib(opus_libs=OPUS_LIBS):
    try:
        if opus.is_loaded():

            return True

        for opus_lib in opus_libs:
            try:
                opus.load_opus(opus_lib)
                return
            except OSError:
                pass

        raise RuntimeError('Could not load an opus lib. Tried %s' %
                           (', '.join(opus_libs)))
    except Exception as e:
        print(str(e), flush=True)
示例#26
0
def load_opus_lib(opus_libs):
    """ TODO """
    if opus_libs is None:
        opus_libs = OPUS_LIBS

    if opus.is_loaded():
        return True

    for opus_lib in opus_libs:
        try:
            opus.load_opus(opus_lib)
            return
        except OSError:
            pass

    raise RuntimeError("Could not load an opus lib. Tried %s" %
                       (', '.join(opus_libs)))
示例#27
0
文件: bot.py 项目: Combine12/NeatoBot
async def on_ready():
    #channel = discord.Channel()
    #aerver = discord.Server()
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')
    #await client.change_status(game=discord.Game(name='Robot Factory on Hard'))
    stat = open("status.txt", "r")
    await bot.change_status(game=discord.Game(name=stat.read()))
    stat.close()
    opus.load_opus("C:/NeatoBot/discord/bin/libopus-0.x86.dll")
    if opus.is_loaded():
        await bot.send_message(generalChannel, "Successfully loaded the Opus library.")
    #await bot.send_message(generalChannel, "Read status")
    #await bot.send_message(generalChannel, "Set status")
    #await bot.send_message(generalChannel, "First init of chat AI")
    #await bot.send_message(generalChannel, "Loaded commands")
    voiceClient = "none"
    await bot.send_message(generalChannel, "Combot fully loaded!")
示例#28
0
def load_opus_lib():

    opus_libs = [
        'libopus-0.x86.dll', 'libopus-0.x64.dll', 'libopus-0.dll',
        'libopus.so.0', 'libopus.0.dylib'
    ]

    if opus.is_loaded():
        print('Opus loaded')
        return True

    for opus_lib in opus_libs:
        try:
            opus.load_opus(opus_lib)
            print("Manually loaded {}".format(opus_lib))
            return
        except OSError:
            pass

    raise RuntimeError('Could not load an opus lib. Tried %s' %
                       (', '.join(opus_libs)))
示例#29
0
async def on_ready():
    ram.debug = C.is_test
    await other.busy()
    log.I(
        f'Logged in as {C.client.user} (id: {C.client.user.id}, Test: {C.is_test})'
    )
    prepare_const2()
    emj.prepare()
    await ev.load()
    ram.debug = ram.debug or C.is_test
    if not discord__opus.is_loaded():
        lb = find_library("opus")
        log.jD('opus lib: ', lb)  # i can't find it on heroku
        if lb:
            discord__opus.load_opus(lb)
        else:
            log.jI('opus lib not load!')
    ev.start_timers()
    log.I('Beckett ready for work now, after starting at ',
          ram.t_start.strftime('[%d/%m/%y %T]'))
    log.p('======= ' * 10)
    await test_fun()  # for debugging an testing
    C.Ready = True
    await other.test_status(ram.game)
示例#30
0
import os
import discord
from dotenv import load_dotenv
from discord import opus
from guild_user_manager import GuidManager
from lenny_face import random_lenny_face
print(opus.is_loaded())

#opus.load_opus('C:\\Users\Dan\\opus\\libopus-0.dll')

load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')


class MyClient(discord.Client):
    def __init__(self):
        super().__init__()
        self.myguild = GuidManager()
        self._voice_client = None

    async def on_ready(self):
        guild = discord.utils.get(self.guilds, name=GUILD)
        print(guild)
        self.myguild.init(guild=guild)

    async def on_message(self, message):
        global VC
        if message.author == self.user:
            await message.author.edit(nick=random_lenny_face())
            return
示例#31
0
import re
from collections import OrderedDict
from configparser import ConfigParser, NoOptionError, NoSectionError
from hashlib import md5
from random import randint
from tempfile import gettempdir

from discord import ChannelType, opus
from yandex_speech import TTS

from .cmdprocessor import CommandProcessor
from .mydiscord import MyDiscord

tts_voices = ['jane', 'oksana', 'alyss', 'omazh', 'zahar', 'ermil']

if not opus.is_loaded():
    opus.load_opus('voice')

config = ConfigParser()
config.read_file(codecs.open('config.ini', 'r', 'utf-8'))

client = MyDiscord()
try:
    client.token = config.get('discord', 'token')
except (NoSectionError, NoOptionError):
    print("No config option - discord/token")

voice = None
voice_volume = 1.0
try:
    voice_volume = float(config.get('voice', 'volume')) / 100.0
示例#32
0
async def on_connect():
    print("Attempting to load OPUS...")
    opus.load_opus(ctypes.util.find_library("opus"))
    print("OPUS loaded: " + str(opus.is_loaded()))
示例#33
0
 def check_opus():
     if not opus.is_loaded():
         opus.load_opus("dll/opus/libopus-0.dll")
     return opus.is_loaded()
示例#34
0
import json
import logging

from discord import opus
from discord.ext import commands

from disco import discobot

with open('config.json') as f:
    config = json.load(f)

format = '%(asctime)s ::%(levelname)s:: %(message)s'
datefmt = '%Y-%m-%d %H:%M:%S'
level = getattr(logging, config.get('log-level', 'info').upper())
logging.basicConfig(format=format, datefmt=datefmt, level=level)

if not opus.is_loaded():
    opus.load_opus(config['opus-library-path'])

bot = discobot.DiscoBot(commands.when_mentioned)

import disco.events
import disco.commands
示例#35
0
 def load_opus(self):
     opus_path = find_library('opus')
     opus.load_opus(opus_path)
     if not opus.is_loaded():
     	print('Opus was not loaded')
     	self.bot.loop.stop()