
Recherche avancée
Autres articles (84)
-
Amélioration de la version de base
13 septembre 2013Jolie sélection multiple
Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...) -
Configuration spécifique pour PHP5
4 février 2011, parPHP5 est obligatoire, vous pouvez l’installer en suivant ce tutoriel spécifique.
Il est recommandé dans un premier temps de désactiver le safe_mode, cependant, s’il est correctement configuré et que les binaires nécessaires sont accessibles, MediaSPIP devrait fonctionner correctement avec le safe_mode activé.
Modules spécifiques
Il est nécessaire d’installer certains modules PHP spécifiques, via le gestionnaire de paquet de votre distribution ou manuellement : php5-mysql pour la connectivité avec la (...) -
ANNEXE : Les plugins utilisés spécifiquement pour la ferme
5 mars 2010, parLe site central/maître de la ferme a besoin d’utiliser plusieurs plugins supplémentaires vis à vis des canaux pour son bon fonctionnement. le plugin Gestion de la mutualisation ; le plugin inscription3 pour gérer les inscriptions et les demandes de création d’instance de mutualisation dès l’inscription des utilisateurs ; le plugin verifier qui fournit une API de vérification des champs (utilisé par inscription3) ; le plugin champs extras v2 nécessité par inscription3 (...)
Sur d’autres sites (4392)
-
How to create a command – Introducing the Piwik Platform
2 octobre 2014, par Thomas Steur — DevelopmentThis is the next post of our blog series where we introduce the capabilities of the Piwik platform (our previous post was How to publish your plugin or theme on the Piwik Marketplace). This time you’ll learn how to create a new command. For this tutorial you will need to have basic knowledge of PHP.
What is a command ?
A command can execute any task on the command line. Piwik provides currently about 50 commands via the Piwik Console. These commands let you start the archiver, change the number of available custom variables, enable the developer mode, clear caches, run tests and more. You could write your own command to sync users or websites with another system for instance.
Getting started
In this series of posts, we assume that you have already set up your development environment. If not, visit the Piwik Developer Zone where you’ll find the tutorial Setting up Piwik.
To summarize the things you have to do to get setup :
- Install Piwik (for instance via git).
- Activate the developer mode :
./console development:enable --full
. - Generate a plugin :
./console generate:plugin --name="MyCommandPlugin"
. There should now be a folderplugins/MyCommandPlugin
. - And activate the created plugin under Settings => Plugins.
Let’s start creating a command
We start by using the Piwik Console to create a new command. As you can see there is even a command that lets you easily create a new command :
./console generate:command
The command will ask you to enter the name of the plugin the created command should belong to. I will simply use the above chosen plugin name “MyCommandPlugin”. It will ask you for a command name as well. I will use “SyncUsers” in this example. There should now be a file
plugins/MyCommandPlugin/Commands/Syncusers.php
which contains already an example to get you started easily :- class Syncusers extends ConsoleCommand
- {
- protected function configure()
- {
- $this->setName('mycommandplugin:syncusers');
- $this->setDescription('MyCommandPlugin');
- $this->addOption('name', null, InputOption::VALUE_REQUIRED, 'Your name:');
- }
- /**
- * Execute command like: ./console mycommandplugin:syncusers --name="The Piwik Team"
- */
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $name = $input->getOption('name');
- $output->writeln($message);
- }
- }
Any command that is placed in the “Commands” folder of your plugin will be available on the command line automatically. Therefore, the newly created command can now be executed via
./console mycommandplugin:syncusers --name="The Piwik Team"
.The code template explained
- protected function configure()
- {
- $this->setName('mycommandplugin:checkdatabase');
- $this->setDescription('MyCommandPlugin');
- $this->addOption('name', null, InputOption::VALUE_REQUIRED, 'Your name:');
- }
As the name says the method
configure
lets you configure your command. You can define the name and description of your command as well as all the options and arguments you expect when executing it.- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $name = $input->getOption('name');
- $output->writeln($message);
- }
The actual task is defined in the
execute
method. There you can access any option or argument that was defined on the command line via$input
and write anything to the console via$output
argument.In case anything went wrong during the execution you should throw an exception to make sure the user will get a useful error message. Throwing an exception when an error occurs will make sure the command does exit with a status code different than 0 which can sometimes be important.
Advanced features
The Piwik Console is based on the powerful Symfony Console component. For instance you can ask a user for any interactive input, you can use different output color schemes and much more. If you are interested in learning more all those features have a look at the Symfony console website.
How to test a command
After you have created a command you are surely wondering how to test it. Ideally, the actual command is quite short as it acts like a controller. It should only receive the input values, execute the task by calling a method of another class and output any useful information. This allows you to easily create a unit or integration test for the classes behind the command. We will cover this topic in one of our future blog posts. Just one hint : You can use another command
./console generate:test
to create a test. If you want to know how to test a command have a look at the Testing Commands documentation.Publishing your Plugin on the Marketplace
In case you want to share your commands with other Piwik users you can do this by pushing your plugin to a public GitHub repository and creating a tag. Easy as that. Read more about how to distribute a plugin and best practices when publishing a plugin.
Isn’t it easy to create a command ? We never even created a file ! If you have any feedback regarding our APIs or our guides in the Developer Zone feel free to send it to us.
-
Why is my discord bot not able to find the file that is there when I open the folder manually ?
22 juin 2021, par TomaI made a discord bot that should play music using ffmpeg.


It's connecting and downloading the youtube webm file after which it should convert and rename it to
song.mp3
but it doesn't manage to do so. I check the folder and the error message doesn't match what I see - the file is there and has been renamed.

- 

- Am I using the replace command correctly to move the file ?
- I'd note that I'm using windows10 and that the folders are all read only and that although I'm the admin I can't change that no matter what I do (I guess it's a win10 bug). Does that have anything to do with it ?
- Is there another mistake in the code that'd prevent the file from being found by the bot ?








My code :


import discord
from discord.ext import commands
import youtube_dl #for url music command
import os

client = commands.Bot(command_prefix = '><')

#connect to voice channel
@client.command(aliases = ['c'])
async def connect(ctx, vcName):
 voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
 voiceChannel = discord.utils.get(ctx.guild.channels, name=str(vcName))
 if voice == None: #if voice is not connected to any channel
 await voiceChannel.connect()
 else:
 if voice.channel == vcName: #if trying to connect to the same channel
 await ctx.send('already connected to this channel')
 else:
 await voice.move_to(vcName)

@client.command(aliases = ['d'])
async def delFile(ctx):
 song_there = os.path.exists(os.getcwd()+'/music/current/song.mp3') #true when song.mp3 exists in 'current' folder in 'music' folder
 if song_there:
 await ctx.send('song was detected')
 os.remove('song.mp3')
 if song_there:
 await ctx.send('song was not deleted')
 else:
 await ctx.send('File is not found. check the name again')

#play music from url

@client.command(aliases = ['p'])
async def playMusic(ctx, vcName, url : str): #play music file
 song_there = os.path.exists(os.path.join(os.getcwd(),'/music/current/song.mp3'))
 try:
 if song_there:
 print('previous song found')
 os.remove(os.path.join(os.getcwd(),'/music/current/song.mp3')) #removes the song in current to make room for a new song
 if song_there:
 print('song was not deleted')
 else:
 print('song deleted')
 except PermissionError:
 await ctx.send('A song is currently playing')
 return
 voiceChannel = discord.utils.get(ctx.guild.channels, name=str(vcName))
 ydl_opts = {
 'format': 'bestaudio/best',
 'postprocessors': [{
 'key': 'FFmpegExtractAudio',
 'preferredcodec': 'mp3',
 'preferredquality': '192',
 }]
 }


 for file in os.listdir('./'):
 if file.endswith('.mp3'): #if song.mp3 already exists delete it to make room for a new download
 os.remove('song.mp3')
 else: #download the file from youtube
 with youtube_dl.YoutubeDL(ydl_opts) as ydl:
 ydl.download([url])
 for file in os.listdir('./'): #after downloading rename the file and move it to current folder
 if not file == ('song.mp3') and file.endswith('.mp3'):
 os.rename(file, 'song.mp3')
 print(os.path.join(os.getcwd(), 'song.mp3'))
 print(os.path.join(os.getcwd(), '/music/current/song.mp3'))
 os.replace(os.path.join(os.getcwd(), 'song.mp3'), os.path.join(os.getcwd(), '/music/current/song.mp3')) #move file to current

 voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
 if not voice is None: #if voice is already created
 if not voice.is_connected(): #and is not connected
 await voiceChannel.connect()
 voice.play(discord.FFmpegPCMAudio('song.mp3'))
 else:
 await ctx.send('Bot made an oopsy. Cast mending and heal bot.')
client.run('token')



Error :


[youtube] wkJ7oDMqz0A: Downloading webpage
[download] The Minor Bee-wkJ7oDMqz0A.webm has already been downloaded
[download] 100% of 5.13MiB
[ffmpeg] Destination: The Minor Bee-wkJ7oDMqz0A.mp3
Deleting original file The Minor Bee-wkJ7oDMqz0A.webm (pass -k to keep)
[youtube] wkJ7oDMqz0A: Downloading webpage
[download] Destination: The Minor Bee-wkJ7oDMqz0A.webm
[download] 100% of 5.13MiB in 00:00 
[ffmpeg] Destination: The Minor Bee-wkJ7oDMqz0A.mp3
Deleting original file The Minor Bee-wkJ7oDMqz0A.webm (pass -k to keep)
[youtube] wkJ7oDMqz0A: Downloading webpage
[download] Destination: The Minor Bee-wkJ7oDMqz0A.webm
[download] 100% of 5.13MiB in 00:00 
[ffmpeg] Destination: The Minor Bee-wkJ7oDMqz0A.mp3
Deleting original file The Minor Bee-wkJ7oDMqz0A.webm (pass -k to keep)
C:.....song.mp3 -> **C:/music/current/song.mp3**
Ignoring exception in command playMusic:
Traceback (most recent call last):
 File "C:\Program Files\Python38\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
 ret = await coro(*args, **kwargs)
 File "C:...tut-bot.py", line 84, in playMusic
 os.replace(os.path.join(os.getcwd(), 'song.mp3'), os.path.join(os.getcwd(), '/music/current/song.mp3')) #move file to current
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\....\\song.mp3' -> 'C:/music/current/song.mp3'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
 File "C:\Program Files\Python38\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
 await ctx.command.invoke(ctx)
 File "C:\Program Files\Python38\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
 await injected(*ctx.args, **ctx.kwargs)
 File "C:\Program Files\Python38\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
 raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\...\\song.mp3' -> 'C:/music/current/song.mp3'



-
Why does my discord bot not able to find the file that is there when I open the folder manually ?
22 juin 2021, par TomaI made a discord bot that should play music using ffmpeg.


It's connecting and downloading the youtube webm file after which it should convert and rename it to
song.mp3
but it doesn't manage to do so. I check the folder and the error message doesn't match what I see - the file is there and has been renamed.

- 

- Am I using the replace command correctly to move the file ?
- I'd note that I'm using windows10 and that the folders are all read only and that although I'm the admin I can't change that no matter what I do (I guess it's a win10 bug). Does that have anything to do with it ?
- Is there another mistake in the code that'd prevent the file from being found by the bot ?








My code :


import discord
from discord.ext import commands
import youtube_dl #for url music command
import os

client = commands.Bot(command_prefix = '><')

#connect to voice channel
@client.command(aliases = ['c'])
async def connect(ctx, vcName):
 voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
 voiceChannel = discord.utils.get(ctx.guild.channels, name=str(vcName))
 if voice == None: #if voice is not connected to any channel
 await voiceChannel.connect()
 else:
 if voice.channel == vcName: #if trying to connect to the same channel
 await ctx.send('already connected to this channel')
 else:
 await voice.move_to(vcName)

@client.command(aliases = ['d'])
async def delFile(ctx):
 song_there = os.path.exists(os.getcwd()+'/music/current/song.mp3') #true when song.mp3 exists in 'current' folder in 'music' folder
 if song_there:
 await ctx.send('song was detected')
 os.remove('song.mp3')
 if song_there:
 await ctx.send('song was not deleted')
 else:
 await ctx.send('File is not found. check the name again')

#play music from url

@client.command(aliases = ['p'])
async def playMusic(ctx, vcName, url : str): #play music file
 song_there = os.path.exists(os.path.join(os.getcwd(),'/music/current/song.mp3'))
 try:
 if song_there:
 print('previous song found')
 os.remove(os.path.join(os.getcwd(),'/music/current/song.mp3')) #removes the song in current to make room for a new song
 if song_there:
 print('song was not deleted')
 else:
 print('song deleted')
 except PermissionError:
 await ctx.send('A song is currently playing')
 return
 voiceChannel = discord.utils.get(ctx.guild.channels, name=str(vcName))
 ydl_opts = {
 'format': 'bestaudio/best',
 'postprocessors': [{
 'key': 'FFmpegExtractAudio',
 'preferredcodec': 'mp3',
 'preferredquality': '192',
 }]
 }


 for file in os.listdir('./'):
 if file.endswith('.mp3'): #if song.mp3 already exists delete it to make room for a new download
 os.remove('song.mp3')
 else: #download the file from youtube
 with youtube_dl.YoutubeDL(ydl_opts) as ydl:
 ydl.download([url])
 for file in os.listdir('./'): #after downloading rename the file and move it to current folder
 if not file == ('song.mp3') and file.endswith('.mp3'):
 os.rename(file, 'song.mp3')
 print(os.path.join(os.getcwd(), 'song.mp3'))
 print(os.path.join(os.getcwd(), '/music/current/song.mp3'))
 os.replace(os.path.join(os.getcwd(), 'song.mp3'), os.path.join(os.getcwd(), '/music/current/song.mp3')) #move file to current

 voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
 if not voice is None: #if voice is already created
 if not voice.is_connected(): #and is not connected
 await voiceChannel.connect()
 voice.play(discord.FFmpegPCMAudio('song.mp3'))
 else:
 await ctx.send('Bot made an oopsy. Cast mending and heal bot.')
client.run('token')



Error :


[youtube] wkJ7oDMqz0A: Downloading webpage
[download] The Minor Bee-wkJ7oDMqz0A.webm has already been downloaded
[download] 100% of 5.13MiB
[ffmpeg] Destination: The Minor Bee-wkJ7oDMqz0A.mp3
Deleting original file The Minor Bee-wkJ7oDMqz0A.webm (pass -k to keep)
[youtube] wkJ7oDMqz0A: Downloading webpage
[download] Destination: The Minor Bee-wkJ7oDMqz0A.webm
[download] 100% of 5.13MiB in 00:00 
[ffmpeg] Destination: The Minor Bee-wkJ7oDMqz0A.mp3
Deleting original file The Minor Bee-wkJ7oDMqz0A.webm (pass -k to keep)
[youtube] wkJ7oDMqz0A: Downloading webpage
[download] Destination: The Minor Bee-wkJ7oDMqz0A.webm
[download] 100% of 5.13MiB in 00:00 
[ffmpeg] Destination: The Minor Bee-wkJ7oDMqz0A.mp3
Deleting original file The Minor Bee-wkJ7oDMqz0A.webm (pass -k to keep)
C:.....song.mp3 -> **C:/music/current/song.mp3**
Ignoring exception in command playMusic:
Traceback (most recent call last):
 File "C:\Program Files\Python38\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
 ret = await coro(*args, **kwargs)
 File "C:...tut-bot.py", line 84, in playMusic
 os.replace(os.path.join(os.getcwd(), 'song.mp3'), os.path.join(os.getcwd(), '/music/current/song.mp3')) #move file to current
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\....\\song.mp3' -> 'C:/music/current/song.mp3'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
 File "C:\Program Files\Python38\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
 await ctx.command.invoke(ctx)
 File "C:\Program Files\Python38\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
 await injected(*ctx.args, **ctx.kwargs)
 File "C:\Program Files\Python38\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
 raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\...\\song.mp3' -> 'C:/music/current/song.mp3'