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
Loïc DEFRANCE
PlayBot
Validations
be23a30f
Valider
be23a30f
rédigé
Il y a 10 ans
par
Alexandre Morignot
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
New object utils::db::query
parent
55997080
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
lib/commands/get.pm
+13
-108
13 ajouts, 108 suppressions
lib/commands/get.pm
avec
13 ajouts
et
108 suppressions
lib/commands/get.pm
+
13
−
108
Voir le fichier @
be23a30f
...
...
@@ -6,16 +6,13 @@ use warnings;
use
lib
"
$FindBin
::Bin/lib/
";
use
utils::
print
;
use
utils::
db
;
use
utils::db::
query
;
use
commands::get::
query
;
our
$irc
;
our
$log
;
my
%last_req
;
my
$dbh
;
my
$sth
;
sub
exec
{
my
(
$kernel
,
$nick
,
$chan
,
$msg
)
=
@_
;
...
...
@@ -24,100 +21,12 @@ sub exec {
query
=>
(
$msg
)
?
$msg
:
''
);
my
$content
;
my
$req
;
my
$rows
;
if
(
not
defined
$last_req
{
$query
->
chan
}
or
not
(
$query
~~
$last_req
{
$query
->
chan
}))
{
# we close a previous session if needed
if
(
$dbh
)
{
$sth
->
finish
if
$sth
->
{'
Active
'};
$dbh
->
commit
;
$dbh
->
disconnect
;
}
$dbh
=
utils::db::
get_new_session
;
my
@words_param
;
foreach
(
@
{
$query
->
words
})
{
unshift
@words_param
,
'
%
'
.
$_
.
'
%
';
}
my
$words_sql
;
foreach
(
@
{
$query
->
words
})
{
$words_sql
.=
'
and
'
if
(
$words_sql
);
$words_sql
.=
"
concat(sender, ' ', title) like ?
";
}
if
(
$query
->
id
>=
0
)
{
$sth
=
$dbh
->
prepare
('
select id, sender, title, url, duration
from playbot
where id = ?
');
$sth
->
execute
(
$query
->
id
);
}
elsif
(
@
{
$query
->
tags
})
{
my
@where
;
foreach
my
$tag
(
@
{
$query
->
tags
})
{
unshift
@where
,
'
p.id in (select pt.id from playbot_tags pt where pt.tag = ?)
';
}
my
$where
=
join
'
and
'
=>
@where
;
if
(
$query
->
is_global
)
{
$req
=
'
select id, sender, title, url, duration
from playbot p
where
'
.
$where
;
$req
.=
'
and
'
.
$words_sql
if
(
$words_sql
);
$req
.=
'
group by id
order by rand()
';
$sth
=
$dbh
->
prepare
(
$req
);
$sth
->
execute
(
@
{
$query
->
tags
},
@words_param
);
}
else
{
$req
=
'
select p.id, p.sender, p.title, p.url, duration
from playbot p
join playbot_chan pc on p.id = pc.content
where
'
.
$where
;
$req
.=
'
and
'
.
$words_sql
if
(
$words_sql
);
$req
.=
'
and pc.chan = ?
group by p.id
order by rand()
';
$sth
=
$dbh
->
prepare
(
$req
);
$sth
->
execute
(
@
{
$query
->
tags
},
@words_param
,
$query
->
chan
);
}
}
else
{
if
(
$query
->
is_global
)
{
$req
=
'
select id, sender, title, url, duration from playbot
';
$req
.=
'
where
'
.
$words_sql
if
(
$words_sql
);
$req
.=
'
group by id
';
$req
.=
'
order by rand()
';
$sth
=
$dbh
->
prepare
(
$req
);
$sth
->
execute
(
@words_param
);
}
else
{
$req
=
'
select p.id, p.sender, p.title, p.url, duration
from playbot p
join playbot_chan pc on p.id = pc.content
where pc.chan = ?
';
$req
.=
'
and
'
.
$words_sql
if
(
$words_sql
);
$req
.=
'
group by p.id
';
$req
.=
'
order by rand()
';
$sth
=
$dbh
->
prepare
(
$req
);
$sth
->
execute
(
$query
->
chan
,
@words_param
);
}
}
}
$content
=
$sth
->
fetch
;
my
$db_query
=
utils::db::
query
->
new
();
my
$content
=
$db_query
->
get
(
$query
);
my
$rows
=
$db_query
->
get_rows
(
$query
);
if
(
!
$content
)
{
if
(
$
last_req
{
$query
->
chan
}
~~
$query
)
{
if
(
$
rows
>
0
)
{
# the request was already executed, there is nothing more
$irc
->
yield
(
privmsg
=>
$chan
=>
"
Tu tournes en rond, Jack !
");
}
...
...
@@ -128,21 +37,18 @@ sub exec {
$irc
->
yield
(
privmsg
=>
$chan
=>
"
Poste d'abord du contenu, n00b.
");
}
$last_req
{
$query
->
chan
}
=
undef
;
return
}
# this is specific to the mysql driver
$rows
=
$sth
->
rows
;
my
$sth2
=
utils::db::
main_session
()
->
prepare
("
select tag
my
$dbh
=
utils::db::
main_session
();
my
$sth
=
$dbh
->
prepare
("
select tag
from playbot_tags
where id = ?
");
$sth
2
->
execute
(
$content
->
[
0
]);
$sth
->
execute
(
$content
->
[
0
]);
my
@tags
;
while
(
my
$data
=
$sth
2
->
fetch
)
{
while
(
my
$data
=
$sth
->
fetch
)
{
my
$tag
=
$data
->
[
0
];
$tag
=~
s/([a-zA-Z0-9_-]+)/#$1/
;
push
@tags
,
$tag
;
...
...
@@ -163,16 +69,15 @@ sub exec {
$irc
->
yield
(
privmsg
=>
$chan
=>
$irc_msg
);
# we save the get like a post
$sth
2
=
utils::db::
main_session
()
->
prepare_cached
('
$sth
=
$dbh
->
prepare_cached
('
INSERT INTO playbot_chan (content, chan, sender_irc)
VALUES (?,?,?)
');
$log
->
error
("
Couldn't prepare querie; aborting
")
unless
(
defined
$sth
2
);
$log
->
error
("
Couldn't prepare querie; aborting
")
unless
(
defined
$sth
);
$sth
2
->
execute
(
$content
->
[
0
],
$chan
->
[
0
],
"
PlayBot
")
$sth
->
execute
(
$content
->
[
0
],
$chan
->
[
0
],
"
PlayBot
")
or
$log
->
error
("
Couldn't finish transaction:
"
.
$dbh
->
errstr
);
# we save the request
$last_req
{
$query
->
chan
}
=
$query
;
$dbh
->
commit
();
return
$content
->
[
0
];
}
...
...
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