mirror of
https://github.com/skylanix/MamieHenriette.git
synced 2026-02-06 14:50:34 +01:00
notification humble bundle
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import datetime
|
import datetime
|
||||||
import discord
|
import discord
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from database import db
|
from database import db
|
||||||
|
from database.helpers import ConfigurationHelper
|
||||||
from database.models import Configuration, GameBundle, Humeur
|
from database.models import Configuration, GameBundle, Humeur
|
||||||
|
|
||||||
class DiscordBot(discord.Client):
|
class DiscordBot(discord.Client):
|
||||||
@@ -18,29 +20,36 @@ class DiscordBot(discord.Client):
|
|||||||
self.loop.create_task(self.updateHumbleBundle())
|
self.loop.create_task(self.updateHumbleBundle())
|
||||||
|
|
||||||
async def updateStatus(self):
|
async def updateStatus(self):
|
||||||
humeur = random.choice(Humeur.query.all())
|
while not self.is_closed():
|
||||||
if humeur != None:
|
humeur = random.choice(Humeur.query.all())
|
||||||
logging.info(f'changement de status {humeur.text}')
|
if humeur != None:
|
||||||
await self.change_presence(status = discord.Status.online, activity = discord.CustomActivity(humeur.text))
|
logging.info(f'changement de status {humeur.text}')
|
||||||
await asyncio.sleep(60)
|
await self.change_presence(status = discord.Status.online, activity = discord.CustomActivity(humeur.text))
|
||||||
|
# 10 minutes TODO à rendre configurable
|
||||||
|
await asyncio.sleep(10*60)
|
||||||
|
|
||||||
async def updateHumbleBundle(self):
|
async def updateHumbleBundle(self):
|
||||||
response = requests.get("http://hexas.shionn.org/humble-bundle/json", headers={ "Content-Type": "application/json" })
|
while not self.is_closed():
|
||||||
if response.status_code == 200:
|
if ConfigurationHelper().getValue('humble_bundle_enable') and ConfigurationHelper().getIntValue('humble_bundle_channel') != 0 :
|
||||||
bundle = response.json()
|
response = requests.get("http://hexas.shionn.org/humble-bundle/json", headers={ "Content-Type": "application/json" })
|
||||||
if (GameBundle.query.filter_by(id=bundle['id']).first() == None) :
|
if response.status_code == 200:
|
||||||
choice = bundle['choices'][0]
|
bundle = response.json()
|
||||||
date = datetime.datetime.fromtimestamp(bundle['endDate']/1000,datetime.UTC).strftime("%d %B %Y")
|
if GameBundle.query.filter_by(id=bundle['id']).first() == None :
|
||||||
message = f"@here **Humble Bundle** propose un pack de jeu [{bundle['name']}]({bundle['url']}) contenant :\n"
|
choice = bundle['choices'][0]
|
||||||
for game in choice["games"]:
|
date = datetime.datetime.fromtimestamp(bundle['endDate']/1000,datetime.UTC).strftime("%d %B %Y")
|
||||||
message += f"- {game}\n"
|
message = f"@here **Humble Bundle** propose un pack de jeu [{bundle['name']}]({bundle['url']}) contenant :\n"
|
||||||
message += f"Pour {choice['price']}€, disponible jusqu'au {date}."
|
for game in choice["games"]:
|
||||||
# await self.get_channel(1123512494468644984).send(message)
|
message += f"- {game}\n"
|
||||||
# db.session.add(GameBundle(id=bundle['id'], json = bundle))
|
message += f"Pour {choice['price']}€, disponible jusqu'au {date}."
|
||||||
# db.session.commit()
|
await self.get_channel(ConfigurationHelper().getIntValue('humble_bundle_channel')).send(message)
|
||||||
else:
|
db.session.add(GameBundle(id=bundle['id'], name=bundle['name'], json = json.dumps(bundle)))
|
||||||
logging.error(f"Erreur de connexion {response.status_code}")
|
db.session.commit()
|
||||||
await asyncio.sleep(60)
|
else:
|
||||||
|
logging.error(f"Erreur de connexion {response.status_code}")
|
||||||
|
else:
|
||||||
|
logging.info('Humble bundle est désactivé')
|
||||||
|
# toute les 30 minutes
|
||||||
|
await asyncio.sleep(30*60)
|
||||||
|
|
||||||
def begin(self) :
|
def begin(self) :
|
||||||
token = Configuration.query.filter_by(key='discord_token').first()
|
token = Configuration.query.filter_by(key='discord_token').first()
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
from flask import render_template, request, redirect, url_for
|
from flask import render_template, request, redirect, url_for
|
||||||
from webapp import webapp
|
from webapp import webapp
|
||||||
from database import db
|
from database import db
|
||||||
from database.models import Configuration
|
|
||||||
from database.helpers import ConfigurationHelper
|
from database.helpers import ConfigurationHelper
|
||||||
from discordbot import bot
|
from discordbot import bot
|
||||||
from discord import TextChannel
|
from discord import TextChannel
|
||||||
|
|
||||||
@webapp.route("/configurations")
|
@webapp.route("/configurations")
|
||||||
def openConfigurations():
|
def openConfigurations():
|
||||||
all = Configuration.query.all()
|
|
||||||
channels = []
|
channels = []
|
||||||
for channel in bot.get_all_channels():
|
for channel in bot.get_all_channels():
|
||||||
if isinstance(channel, TextChannel):
|
if isinstance(channel, TextChannel):
|
||||||
|
|||||||
Reference in New Issue
Block a user