Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
S
SMAW
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
Extraits de code
Déploiement
Releases
Registre de paquets
Registre de conteneurs
Registre de modèles
Opération
Modules Terraform
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
bakaclub
SMAW
Validations
ab9984ef
Valider
ab9984ef
rédigé
21 déc. 2020
par
Elliu
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Adding Entry class to support multiples subreddits
parent
70c9a327
Branches
Branches contenant la validation
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é
launch.py
+41
-25
41 ajouts, 25 suppressions
launch.py
avec
41 ajouts
et
25 suppressions
launch.py
+
41
−
25
Voir le fichier @
ab9984ef
...
@@ -9,24 +9,36 @@ load_dotenv()
...
@@ -9,24 +9,36 @@ load_dotenv()
TOKEN
=
os
.
getenv
(
'
DISCORD_TOKEN
'
)
TOKEN
=
os
.
getenv
(
'
DISCORD_TOKEN
'
)
SECRET
=
os
.
getenv
(
'
REDDIT_SECRET
'
)
SECRET
=
os
.
getenv
(
'
REDDIT_SECRET
'
)
subreddit
=
praw
.
Reddit
(
client_id
=
'
yvXh2hrDELw6eg
'
,
\
subreddits
=
dict
()
client_secret
=
SECRET
,
\
user_agent
=
'
KumikoBot
'
).
subreddit
(
'
rarekumikos
'
)
class
Entry
:
hot_subreddit
=
subreddit
.
hot
(
limit
=
500
)
name
=
""
subName
=
""
#subreddit
#hot_subredditu
totalimgs
=
0
totalimgs
=
0
posts
=
[]
posts
=
[]
authors
=
[]
authors
=
[]
posturls
=
[]
posturls
=
[]
def
refresh_posts
():
print
(
'
Refreshing posts!
'
)
def
__init__
(
name
,
subName
):
posts
.
clear
()
self
.
subreddit
=
praw
.
Reddit
(
client_id
=
'
yvXh2hrDELw6eg
'
,
\
authors
.
clear
()
client_secret
=
SECRET
,
\
posturls
.
clear
()
user_agent
=
'
SMAW
'
).
subreddit
(
subName
)
global
totalimgs
hot_subreddit
=
self
.
subreddit
.
hot
(
limit
=
500
)
totalimgs
=
0
def
refresh_posts
(
entry
):
print
(
'
Refreshing posts for
'
+
entry
.
name
+
'
!
'
)
entry
.
posts
.
clear
()
entry
.
authors
.
clear
()
entry
.
posturls
.
clear
()
entry
.
totalimgs
=
0
i
=
0
i
=
0
for
submission
in
subreddit
.
hot
(
limit
=
500
):
for
submission
in
entry
.
subreddit
.
hot
(
limit
=
500
):
#_ = os.system('clear')
#_ = os.system('clear')
i
=
i
+
1
i
=
i
+
1
totalimgs
=
totalimgs
+
1
totalimgs
=
totalimgs
+
1
...
@@ -36,11 +48,15 @@ def refresh_posts():
...
@@ -36,11 +48,15 @@ def refresh_posts():
print
(
str
(
submission
.
url
))
print
(
str
(
submission
.
url
))
totalimgs
=
totalimgs
-
1
totalimgs
=
totalimgs
-
1
continue
continue
posts
.
append
(
submission
.
url
)
entry
.
posts
.
append
(
submission
.
url
)
authors
.
append
(
submission
.
author
)
entry
.
authors
.
append
(
submission
.
author
)
posturls
.
append
(
submission
.
permalink
)
entry
.
posturls
.
append
(
submission
.
permalink
)
print
(
'
Total amount of images:
'
+
str
(
totalimgs
))
print
(
'
Total amount of images:
'
+
str
(
totalimgs
))
def
refresh_all_posts
():
for
entry
in
subreddits
:
refresh_posts
(
entry
)
def
create_embed
(
post
,
author
,
posturl
):
def
create_embed
(
post
,
author
,
posturl
):
embed
=
discord
.
Embed
(
embed
=
discord
.
Embed
(
...
@@ -50,8 +66,7 @@ def create_embed(post,author,posturl):
...
@@ -50,8 +66,7 @@ def create_embed(post,author,posturl):
embed
.
description
=
'
[
'
+
str
(
author
)
+
'
](https://www.reddit.com
'
+
str
(
posturl
)
+
'
)
'
embed
.
description
=
'
[
'
+
str
(
author
)
+
'
](https://www.reddit.com
'
+
str
(
posturl
)
+
'
)
'
return
embed
return
embed
refresh_posts
()
refresh_all_posts
()
client
=
discord
.
Client
()
client
=
discord
.
Client
()
@client.event
@client.event
...
@@ -62,9 +77,10 @@ async def on_ready():
...
@@ -62,9 +77,10 @@ async def on_ready():
async
def
on_message
(
message
):
async
def
on_message
(
message
):
if
message
.
author
==
client
.
user
:
if
message
.
author
==
client
.
user
:
return
return
if
"
showmeakumiko
"
in
message
.
content
.
lower
().
replace
(
'
'
,
''
):
if
"
showmea
"
in
message
.
content
.
lower
().
replace
(
'
'
,
''
):
postnumber
=
random
.
randint
(
1
,
totalimgs
)
if
name
in
subreddits
:
await
message
.
channel
.
send
(
embed
=
create_embed
(
posts
[
postnumber
],
authors
[
postnumber
],
posturls
[
postnumber
]))
postnumber
=
random
.
randint
(
1
,
subreddits
[
name
].
totalimgs
)
await
message
.
channel
.
send
(
embed
=
create_embed
(
subreddits
[
name
].
posts
[
postnumber
],
subreddits
[
name
].
authors
[
postnumber
],
subreddits
[
name
].
posturls
[
postnumber
]))
if
"
refresh the kumikos
"
in
message
.
content
.
lower
():
if
"
refresh the kumikos
"
in
message
.
content
.
lower
():
refresh_posts
()
refresh_posts
()
...
...
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