示例#1
0
文件: voice.py 项目: xmatea/nerdbot
import process
from pytube import YouTube, Playlist
import io
import asyncio
import subprocess
import shlex
from discord.opus import Encoder
import threading
from datetime import datetime, timedelta
from types import SimpleNamespace
import re
from youtubesearchpython import VideosSearch
import numpy as np


config = process.readjson('config.json')
speech = process.readjson('speech.json')

# better FFmpegPCMAudio class; thanks https://github.com/Armster15 <3 =========================================
class FFmpegPCMAudio(discord.AudioSource):

	def __init__(self, source, *, executable='ffmpeg', pipe=False, stderr=None, before_options=None, options=None):
		stdin = None if not pipe else source
		args = [executable]
		if isinstance(before_options, str):
			args.extend(shlex.split(before_options))
		args.append('-i')
		args.append('-' if pipe else source)
		args.extend(('-f', 's16le', '-ar', '48000', '-ac', '2', '-loglevel', 'warning'))
		if isinstance(options, str):
			args.extend(shlex.split(options))
示例#2
0
import discord
from discord.ext import commands
import datetime
from process import readjson
from mongo import db as mongo
db = mongo.db

speech = readjson('speech.json')
config = readjson('config.json')


class EventHandler(commands.Cog):
    def __init__(self, bot):
        self.hidden = True
        self.bot = bot

    @commands.Cog.listener()
    async def on_guild_join(self, guild):
        mongo.insert(guild, mongo.guildModel, db.guilds)
        channel = self.bot.get_guild(config.home_guild).get_channel(
            config.log_channel)
        await channel.send(embed=discord.Embed(
            title="Joined new server!",
            description=
            f"**Name:** {guild.name}\n**Size:** {guild.member_count-1} members\nCurrently in {len(self.bot.guilds)} servers!"
        ))

    @commands.Cog.listener()
    async def on_guild_remove(self, guild):
        mongo.remove({"_id": guild.id}, db.guilds)
        channel = self.bot.get_guild(config.home_guild).get_channel(
示例#3
0
# init
import discord
from discord.ext import commands
from dotenv import load_dotenv
import os
from datetime import date, datetime
import process
import logging

# load and read configurations
load_dotenv()
TOKEN = os.getenv("TOKEN");
DEV = os.getenv("DEV");
Config = process.readjson('config.json')
logging.basicConfig(level=logging.INFO)
prefix = Config.prefix

if DEV == 'True':
    prefix = os.getenv("PREFIX")

# define NerdBot class
class NerdBot(commands.Bot):
    def __init__(self):
        super().__init__(command_prefix=prefix)

# create bot instance
bot = NerdBot()

# read and load command groups
bot.remove_command('help')
bot.remove_cog('general')