Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
P
PlayBot
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Wiki externe
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Déploiement
Releases
Registre de modèles
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Alexandre MORIGNOT
PlayBot
Validations
7f597193
Valider
7f597193
rédigé
6 août 2013
par
Alexandre Morignot
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
New module 'parser'
parent
253c6b67
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
PlayBot.pl
+73
-108
73 ajouts, 108 suppressions
PlayBot.pl
lib/parser.pm
+40
-0
40 ajouts, 0 suppression
lib/parser.pm
avec
113 ajouts
et
108 suppressions
PlayBot.pl
+
73
−
108
Voir le fichier @
7f597193
...
...
@@ -13,12 +13,7 @@ use FindBin;
use
lib
"
$FindBin
::Bin/lib/
";
use
Logging
;
use
sites::
youtube
qw(youtube)
;
use
sites::
soundcloud
qw(soundcloud)
;
use
sites::
mixcloud
qw(mixcloud)
;
use
sites::
zippy
qw(zippy)
;
use
parser
;
# nom du fichier
my
$bot
=
$
0
;
...
...
@@ -265,92 +260,25 @@ sub on_speak
{
my
(
$kernel
,
$user
,
$chan
,
$msg
)
=
@_
[
KERNEL
,
ARG0
,
ARG1
,
ARG2
];
my
(
$nick
,
$mask
)
=
split
(
/!/
,
$user
);
my
$site
;
my
%content
;
if
(
$msg
=~
m#(^|[^!])https?://(www.youtube.com/watch\?[a-zA-Z0-9_=&-]*v=|youtu.be/)([a-zA-Z0-9_-]+)#
)
{
my
$url
=
'
https://www.youtube.com/watch?v=
'
.
$
3
;
eval
{
%content
=
youtube
(
$url
)
};
$site
=
'
youtube
';
}
elsif
(
$msg
=~
m#(^|[^!])https?://soundcloud.com/([a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+)#
)
{
my
$url
=
'
https://www.soundcloud.com/
'
.
$
2
;
eval
{
%content
=
soundcloud
(
$url
)
};
$site
=
'
soundcloud
';
}
elsif
(
$msg
=~
m#(^|[^!])https?://www.mixcloud.com/([a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+)#
)
{
my
$url
=
'
https://www.mixcloud.com/
'
.
$
2
;
eval
{
%content
=
mixcloud
(
$url
)
};
$site
=
'
mixcloud
';
}
elsif
(
$msg
=~
m#((^|[^!])http://www[0-9]+.zippyshare.com/v/[0-9]+/file.html)#
)
{
my
$url
=
$
1
;
eval
{
%content
=
zippy
(
$url
)
};
$site
=
'
zippyshare
';
}
elsif
(
$msg
=~
/^!fav( ([0-9]+))?/
)
{
my
$id
=
(
$
2
)
?
$
2
:
$lastID
;
my
$sth
=
$dbh
->
prepare_cached
('
SELECT user FROM playbot_codes WHERE nick = ?
');
$sth
->
execute
(
$nick
)
or
$log
->
error
("
Couldn't finish transaction:
"
.
$dbh
->
errstr
);
unless
(
$sth
->
rows
)
{
$irc
->
yield
(
privmsg
=>
$nick
=>
"
Ce nick n'est associé à aucun login arise. Va sur http://nightiies.iiens.net/links/fav pour obtenir ton code personel.
");
return
;
}
my
$sth2
=
$dbh
->
prepare_cached
('
INSERT INTO playbot_fav (id, user) VALUES (?, ?)
');
$sth2
->
execute
(
$id
,
$sth
->
fetch
->
[
0
])
or
$log
->
error
("
Couldn't finish transaction:
"
.
$dbh
->
errstr
);
return
;
}
elsif
(
$msg
=~
/^!later(?: ([0-9]+))?(?: in ([0-9]*)?(h|m|s)?)?/
)
{
my
(
$id
,
$time
,
$unit
)
=
(
$
1
,
$
2
,
$
3
);
$id
=
$lastID
if
(
!
$id
);
$time
=
6
if
(
!
$time
);
$time
*=
(
$unit
eq
'
s
')
?
1
:
(
$unit
eq
'
m
')
?
60
:
3600
;
$kernel
->
delay_set
('
_later
',
$time
,
$nick
,
$id
);
return
;
}
elsif
(
$msg
=~
/^!tag( +([0-9]+))?/
)
{
my
$id
=
(
$
2
)
?
$
2
:
$lastID
;
while
(
$msg
=~
/#([a-zA-Z0-9_-]+)/g
)
{
addTag
(
$id
,
$
1
);
}
return
;
}
elsif
(
$msg
=~
/^!help/
)
{
$irc
->
yield
(
privmsg
=>
$chan
=>
'
!fav [<id>] : enregistre la vidéo dans les favoris
');
$irc
->
yield
(
privmsg
=>
$chan
=>
'
!tag [<id>] <tag1> <tag2> ... : tag la vidéo
');
$irc
->
yield
(
privmsg
=>
$chan
=>
'
!later [<id>] [in <x>[s|m|h]] : vidéo rappelée par query (par défaut temps de 6h)
');
$irc
->
yield
(
privmsg
=>
$chan
=>
'
Sans id précisée, la dernière vidéo postée est utilisée.
');
return
;
}
else
{
return
;
}
%content
=
parser::
parse
(
$msg
);
if
(
$@
)
{
$log
->
warning
(
$@
);
return
;
}
if
(
%content
)
{
if
(
$debug
)
{
$log
->
debug
(
$content
{'
url
'});
}
else
{
# insertion de la vidéo dans la bdd
my
$sth
=
$dbh
->
prepare_cached
('
INSERT INTO playbot (date, type, url, sender_irc, sender, title, chan) VALUES (NOW(),?,?,?,?,?,?)
');
$log
->
error
("
Couldn't prepare querie; aborting
")
unless
(
defined
$sth
);
$sth
->
execute
(
$site
,
$content
{'
url
'},
$nick
,
$content
{'
author
'},
$content
{'
title
'},
$chan
->
[
0
])
$sth
->
execute
(
$
content
{'
site
'}
,
$content
{'
url
'},
$nick
,
$content
{'
author
'},
$content
{'
title
'},
$chan
->
[
0
])
or
$log
->
error
("
Couldn't finish transaction:
"
.
$dbh
->
errstr
);
}
...
...
@@ -387,6 +315,43 @@ sub on_speak
$irc
->
yield
(
privmsg
=>
$chan
=>
'
[
'
.
$id
.
'
]
'
.
$content
{'
title
'})
;
}
}
elsif
(
$msg
=~
/^!fav( ([0-9]+))?/
)
{
my
$id
=
(
$
2
)
?
$
2
:
$lastID
;
my
$sth
=
$dbh
->
prepare_cached
('
SELECT user FROM playbot_codes WHERE nick = ?
');
$sth
->
execute
(
$nick
)
or
$log
->
error
("
Couldn't finish transaction:
"
.
$dbh
->
errstr
);
if
(
!
$sth
->
rows
)
{
$irc
->
yield
(
privmsg
=>
$nick
=>
"
Ce nick n'est associé à aucun login arise. Va sur http://nightiies.iiens.net/links/fav pour obtenir ton code personel.
");
}
else
{
my
$sth2
=
$dbh
->
prepare_cached
('
INSERT INTO playbot_fav (id, user) VALUES (?, ?)
');
$sth2
->
execute
(
$id
,
$sth
->
fetch
->
[
0
])
or
$log
->
error
("
Couldn't finish transaction:
"
.
$dbh
->
errstr
);
}
}
elsif
(
$msg
=~
/^!later(?: ([0-9]+))?(?: in ([0-9]*)?(h|m|s)?)?/
)
{
my
(
$id
,
$time
,
$unit
)
=
(
$
1
,
$
2
,
$
3
);
$id
=
$lastID
if
(
!
$id
);
$time
=
6
if
(
!
$time
);
$time
*=
(
$unit
eq
'
s
')
?
1
:
(
$unit
eq
'
m
')
?
60
:
3600
;
$kernel
->
delay_set
('
_later
',
$time
,
$nick
,
$id
);
}
elsif
(
$msg
=~
/^!tag( +([0-9]+))?/
)
{
my
$id
=
(
$
2
)
?
$
2
:
$lastID
;
while
(
$msg
=~
/#([a-zA-Z0-9_-]+)/g
)
{
addTag
(
$id
,
$
1
);
}
}
elsif
(
$msg
=~
/^!help/
)
{
$irc
->
yield
(
privmsg
=>
$chan
=>
'
!fav [<id>] : enregistre la vidéo dans les favoris
');
$irc
->
yield
(
privmsg
=>
$chan
=>
'
!tag [<id>] <tag1> <tag2> ... : tag la vidéo
');
$irc
->
yield
(
privmsg
=>
$chan
=>
'
!later [<id>] [in <x>[s|m|h]] : vidéo rappelée par query (par défaut temps de 6h)
');
$irc
->
yield
(
privmsg
=>
$chan
=>
'
Sans id précisée, la dernière vidéo postée est utilisée.
');
}
}
# Boucle des events
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
lib/parser.pm
0 → 100644
+
40
−
0
Voir le fichier @
7f597193
package
parser
;
require
Exporter
;
our
@ISA
=
qw(Exporter)
;
our
@EXPORT_OK
=
qw(parse)
;
use
lib
"
$FindBin
::Bin/lib/sites/
";
use
youtube
qw(youtube)
;
use
soundcloud
qw(soundcloud)
;
use
mixcloud
qw(mixcloud)
;
use
zippy
qw(zippy)
;
sub
parse
{
my
$msg
=
@_
[
0
];
my
%content
;
if
(
$msg
=~
m#(^|[^!])https?://(www.youtube.com/watch\?[a-zA-Z0-9_=&-]*v=|youtu.be/)([a-zA-Z0-9_-]+)#
)
{
my
$url
=
'
https://www.youtube.com/watch?v=
'
.
$
3
;
eval
{
%content
=
youtube
(
$url
)
};
$content
{'
site
'}
=
'
youtube
';
}
elsif
(
$msg
=~
m#(^|[^!])https?://soundcloud.com/([a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+)#
)
{
my
$url
=
'
https://www.soundcloud.com/
'
.
$
2
;
eval
{
%content
=
soundcloud
(
$url
)
};
$content
{'
site
'}
=
'
soundcloud
';
}
elsif
(
$msg
=~
m#(^|[^!])https?://www.mixcloud.com/([a-zA-Z0-9-_]+/[a-zA-Z0-9-_]+)#
)
{
my
$url
=
'
https://www.mixcloud.com/
'
.
$
2
;
eval
{
%content
=
mixcloud
(
$url
)
};
$content
{'
site
'}
=
'
mixcloud
';
}
elsif
(
$msg
=~
m#((^|[^!])http://www[0-9]+.zippyshare.com/v/[0-9]+/file.html)#
)
{
my
$url
=
$
1
;
eval
{
%content
=
zippy
(
$url
)
};
$content
{'
site
'}
=
'
zippyshare
';
}
return
%content
;
}
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter