add text & voice channle in config file

This commit is contained in:
Milka64 2021-01-07 20:15:21 +01:00
parent e790569a27
commit 4999c52437
2 changed files with 24 additions and 8 deletions

View file

@ -1,6 +1,8 @@
[DEFAULT]
audio_path = /tmp/
voice_channel = channel_name
text_channel = channel_name
[discord]
token = <discord_token>

View file

@ -56,11 +56,15 @@ class Mybot(commands.Cog):
gif_token=None,
audio_path=None,
nickname=None,
voice_channel=None,
text_channel=None,
):
self.gl_url = gl_url
self.audio_path = audio_path
self.gl_token = gl_token
self.gif_token = gif_token
self.voice_channel = voice_channel
self.text_channel = text_channel
self.bot = bot
self.sounds = []
self.nickname = nickname
@ -148,7 +152,7 @@ class Mybot(commands.Cog):
@commands.command()
async def join(self, ctx):
channel = [x for x in self.bot.get_all_channels() if x.name == "Général"][0]
channel = [x for x in self.bot.get_all_channels() if x.name == self.voice_channel][0]
await channel.connect()
await asyncio.sleep(2)
@ -387,7 +391,7 @@ class Mybot(commands.Cog):
@commands.command(help="Faire dire des choses au bot")
async def say(self, ctx, *message):
sentence = ' '.join(message)
channel = [x for x in self.bot.get_all_channels() if x.name == "général"][0]
channel = [x for x in self.bot.get_all_channels() if x.name == self.text_channel][0]
guild = self.bot.guilds[0]
if sentence.startswith('!'):
command_name = sentence.split()[0].replace('!', '')
@ -567,6 +571,14 @@ def main():
nickname = config['DEFAULT']['nickname']
else:
nickname = None
if "voice_channel" in config['DEFAULT']:
voice_channel = config['DEFAULT']['voice_channel']
else:
voice_channel = None
if "text_channel" in config['DEFAULT']:
text_channel = config['DEFAULT']['text_channel']
else:
text_channel = None
audio_path = config['DEFAULT']['audio_path']
token = config['discord']['token']
gl_url = config['gitlab']['url']
@ -586,7 +598,7 @@ def main():
if kron_choice:
await asyncio.sleep(random.choice(range(3550)))
for channel in bot.get_all_channels():
if channel.name == "général":
if channel.name == text_channel:
current_chan = channel
ctx = await bot.get_context(current_chan.last_message)
ctx.message.content = ""
@ -629,7 +641,7 @@ def main():
if test:
await bot.close()
for channel in bot.get_all_channels():
if channel.name == "général":
if channel.name == text_channel:
current_chan = channel
if nickname:
await bot.user.edit(nick=nickname)
@ -638,7 +650,7 @@ def main():
join = bot.get_command('join')
await join.invoke(ctx)
for channel in bot.get_all_channels():
if channel.name == "Général":
if channel.name == voice_channel:
for member in channel.members:
await member.edit(mute=False)
@ -646,7 +658,7 @@ def main():
async def on_voice_state_update(member, before, after):
if before.channel is None and after.channel:
for channel in bot.get_all_channels():
if channel.name == "général":
if channel.name == text_channel:
current_chan = channel
ctx = await bot.get_context(current_chan.last_message)
ctx.message.author = member
@ -657,11 +669,11 @@ def main():
@aiocron.crontab('*/5 * * * *')
async def pipelette():
for channel in bot.get_all_channels():
if channel.name == "Général" and\
if channel.name == voice_channel and\
len(channel.members) > 1 and\
random.choice([True,True,True]):
for channel in bot.get_all_channels():
if channel.name == "général":
if channel.name == text_channel:
current_chan = channel
await asyncio.sleep(random.choice(range(350)))
ctx = await bot.get_context(current_chan.last_message)
@ -677,6 +689,8 @@ def main():
gif_token=gif_token,
audio_path=audio_path,
nickname=nickname,
voice_channel=voice_channel,
text_channel=text_channel,
)
)
bot.run(token)