INIT Node Controlled Python Bot
This commit is contained in:
274
main.py
Normal file
274
main.py
Normal file
@@ -0,0 +1,274 @@
|
||||
import argparse
|
||||
from discord import Intents, Client, Member
|
||||
from discord.ext import commands
|
||||
from NoiseGatev2 import NoiseGate
|
||||
|
||||
def main(clientId='OTQzNzQyMDQwMjU1MTE1MzA0.Yg3eRA.ZxEbRr55xahjfaUmPY8pmS-RHTY', channelId=367396189529833476, NGThreshold=50, deviceId=1):
|
||||
intents = Intents.default()
|
||||
intents.message_content = True
|
||||
|
||||
client = Client(intents=intents)
|
||||
|
||||
@client.event
|
||||
async def on_ready():
|
||||
print(f'We have logged in as {client.user}')
|
||||
|
||||
channelIdToJoin = client.get_channel(channelId)
|
||||
print("Channel", channelIdToJoin)
|
||||
channelConnection = await channelIdToJoin.connect()
|
||||
print("Joined voice")
|
||||
streamHandler = NoiseGate(
|
||||
_input_device_index=deviceId,
|
||||
_voice_connection=channelConnection,
|
||||
_noise_gate_threshold=NGThreshold)
|
||||
# Start the audio stream
|
||||
streamHandler.run()
|
||||
print("stream running")
|
||||
|
||||
|
||||
client.run(clientId)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("deviceId", type=int, help="The ID of the audio device to use")
|
||||
parser.add_argument("channelId", type=int, help="The ID of the voice channel to use")
|
||||
parser.add_argument("clientId", type=str, help="The discord client ID")
|
||||
parser.add_argument("-n", "--NGThreshold", type=int, help="Change the noisegate threshold. This defaults to 50")
|
||||
args = parser.parse_args()
|
||||
|
||||
if (not args.NGThreshold):
|
||||
args.NGThreshold = 50
|
||||
|
||||
print("Arguments:", args)
|
||||
|
||||
main(
|
||||
clientId=args.clientId,
|
||||
channelId=args.channelId,
|
||||
NGThreshold=args.NGThreshold,
|
||||
deviceId=args.deviceId
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#import asyncio
|
||||
#import functools
|
||||
#import itertools
|
||||
#import math
|
||||
#import random
|
||||
#
|
||||
#import discord
|
||||
#from async_timeout import timeout
|
||||
#from discord.ext import commands
|
||||
#
|
||||
#
|
||||
#class VoiceError(Exception):
|
||||
# pass
|
||||
#
|
||||
#
|
||||
#class VoiceState:
|
||||
# def __init__(self, bot: commands.Bot, ctx: commands.Context):
|
||||
# self.bot = bot
|
||||
# self._ctx = ctx
|
||||
#
|
||||
# self.current = None
|
||||
# self.voice = None
|
||||
# self.next = asyncio.Event()
|
||||
# self.songs = SongQueue()
|
||||
#
|
||||
# self._loop = False
|
||||
# self._volume = 0.5
|
||||
# self.skip_votes = set()
|
||||
#
|
||||
# self.audio_player = bot.loop.create_task(self.audio_player_task())
|
||||
#
|
||||
# def __del__(self):
|
||||
# self.audio_player.cancel()
|
||||
#
|
||||
# @property
|
||||
# def loop(self):
|
||||
# return self._loop
|
||||
#
|
||||
# @loop.setter
|
||||
# def loop(self, value: bool):
|
||||
# self._loop = value
|
||||
#
|
||||
# @property
|
||||
# def volume(self):
|
||||
# return self._volume
|
||||
#
|
||||
# @volume.setter
|
||||
# def volume(self, value: float):
|
||||
# self._volume = value
|
||||
#
|
||||
# @property
|
||||
# def is_playing(self):
|
||||
# return self.voice and self.current
|
||||
#
|
||||
# async def audio_player_task(self):
|
||||
# while True:
|
||||
# self.next.clear()
|
||||
#
|
||||
# if not self.loop:
|
||||
# # Try to get the next song within 3 minutes.
|
||||
# # If no song will be added to the queue in time,
|
||||
# # the player will disconnect due to performance
|
||||
# # reasons.
|
||||
# try:
|
||||
# async with timeout(180): # 3 minutes
|
||||
# self.current = await self.songs.get()
|
||||
# except asyncio.TimeoutError:
|
||||
# self.bot.loop.create_task(self.stop())
|
||||
# return
|
||||
#
|
||||
# self.current.source.volume = self._volume
|
||||
# self.voice.play(self.current.source, after=self.play_next_song)
|
||||
# await self.current.source.channel.send(embed=self.current.create_embed())
|
||||
#
|
||||
# await self.next.wait()
|
||||
#
|
||||
# def play_next_song(self, error=None):
|
||||
# if error:
|
||||
# raise VoiceError(str(error))
|
||||
#
|
||||
# self.next.set()
|
||||
#
|
||||
# def skip(self):
|
||||
# self.skip_votes.clear()
|
||||
#
|
||||
# if self.is_playing:
|
||||
# self.voice.stop()
|
||||
#
|
||||
# async def stop(self):
|
||||
# self.songs.clear()
|
||||
#
|
||||
# if self.voice:
|
||||
# await self.voice.disconnect()
|
||||
# self.voice = None
|
||||
#
|
||||
#
|
||||
#class Music(commands.Cog):
|
||||
# def __init__(self, bot: commands.Bot):
|
||||
# self.bot = bot
|
||||
# self.voice_states = {}
|
||||
#
|
||||
# def get_voice_state(self, ctx: commands.Context):
|
||||
# state = self.voice_states.get(ctx.guild.id)
|
||||
# if not state:
|
||||
# state = VoiceState(self.bot, ctx)
|
||||
# self.voice_states[ctx.guild.id] = state
|
||||
#
|
||||
# return state
|
||||
#
|
||||
# def cog_unload(self):
|
||||
# for state in self.voice_states.values():
|
||||
# self.bot.loop.create_task(state.stop())
|
||||
#
|
||||
# def cog_check(self, ctx: commands.Context):
|
||||
# if not ctx.guild:
|
||||
# raise commands.NoPrivateMessage('This command can\'t be used in DM channels.')
|
||||
#
|
||||
# return True
|
||||
#
|
||||
# async def cog_before_invoke(self, ctx: commands.Context):
|
||||
# ctx.voice_state = self.get_voice_state(ctx)
|
||||
#
|
||||
# async def cog_command_error(self, ctx: commands.Context, error: commands.CommandError):
|
||||
# await ctx.send('An error occurred: {}'.format(str(error)))
|
||||
#
|
||||
# @commands.command(name='join', invoke_without_subcommand=True)
|
||||
# async def _join(self, ctx: commands.Context):
|
||||
# """Joins a voice channel."""
|
||||
#
|
||||
# destination = ctx.author.voice.channel
|
||||
# if ctx.voice_state.voice:
|
||||
# await ctx.voice_state.voice.move_to(destination)
|
||||
# return
|
||||
#
|
||||
# ctx.voice_state.voice = await destination.connect()
|
||||
#
|
||||
# @commands.command(name='summon')
|
||||
# @commands.has_permissions(manage_guild=True)
|
||||
# async def _summon(self, ctx: commands.Context, *, channel: discord.VoiceChannel = None):
|
||||
# """Summons the bot to a voice channel.
|
||||
#
|
||||
# If no channel was specified, it joins your channel.
|
||||
# """
|
||||
#
|
||||
# if not channel and not ctx.author.voice:
|
||||
# raise VoiceError('You are neither connected to a voice channel nor specified a channel to join.')
|
||||
#
|
||||
# destination = channel or ctx.author.voice.channel
|
||||
# if ctx.voice_state.voice:
|
||||
# await ctx.voice_state.voice.move_to(destination)
|
||||
# return
|
||||
#
|
||||
# ctx.voice_state.voice = await destination.connect()
|
||||
#
|
||||
# @commands.command(name='leave', aliases=['disconnect'])
|
||||
# @commands.has_permissions(manage_guild=True)
|
||||
# async def _leave(self, ctx: commands.Context):
|
||||
# """Clears the queue and leaves the voice channel."""
|
||||
#
|
||||
# if not ctx.voice_state.voice:
|
||||
# return await ctx.send('Not connected to any voice channel.')
|
||||
#
|
||||
# await ctx.voice_state.stop()
|
||||
# del self.voice_states[ctx.guild.id]
|
||||
#
|
||||
# @commands.command(name='play')
|
||||
# async def _play(self, ctx: commands.Context, *, search: str):
|
||||
# """Plays a song.
|
||||
#
|
||||
# If there are songs in the queue, this will be queued until the
|
||||
# other songs finished playing.
|
||||
#
|
||||
# This command automatically searches from various sites if no URL is provided.
|
||||
# A list of these sites can be found here: https://rg3.github.io/youtube-dl/supportedsites.html
|
||||
# """
|
||||
#
|
||||
# if not ctx.voice_state.voice:
|
||||
# await ctx.invoke(self._join)
|
||||
#
|
||||
# async with ctx.typing():
|
||||
# try:
|
||||
# source = await YTDLSource.create_source(ctx, search, loop=self.bot.loop)
|
||||
# except YTDLError as e:
|
||||
# await ctx.send('An error occurred while processing this request: {}'.format(str(e)))
|
||||
# else:
|
||||
# song = Song(source)
|
||||
#
|
||||
# await ctx.voice_state.songs.put(song)
|
||||
# await ctx.send('Enqueued {}'.format(str(source)))
|
||||
#
|
||||
# @_join.before_invoke
|
||||
# @_play.before_invoke
|
||||
# async def ensure_voice_state(self, ctx: commands.Context):
|
||||
# if not ctx.author.voice or not ctx.author.voice.channel:
|
||||
# raise commands.CommandError('You are not connected to any voice channel.')
|
||||
#
|
||||
# if ctx.voice_client:
|
||||
# if ctx.voice_client.channel != ctx.author.voice.channel:
|
||||
# raise commands.CommandError('Bot is already in a voice channel.')
|
||||
#
|
||||
#intents = discord.Intents.default()
|
||||
#intents.message_content = True
|
||||
#
|
||||
#bot = commands.Bot('music.', description="Brent's Revenge", intents=intents)
|
||||
#bot.add_cog(Music(bot))
|
||||
#
|
||||
#
|
||||
#@bot.event
|
||||
#async def on_ready():
|
||||
# print('Logged in as:\n{0.user.name}\n{0.user.id}'.format(bot))
|
||||
#
|
||||
#bot.run('OTQzNzQyMDQwMjU1MTE1MzA0.Yg3eRA.ZxEbRr55xahjfaUmPY8pmS-RHTY')
|
||||
Reference in New Issue
Block a user