def planifie(channel_obj: discord.Channel = None):
now = int(time.time())
thisDay = now - (now % 86400)
seconds_left = 86400 - (now - thisDay)
multiplicator = round(seconds_left / 86400, 5)
if not channel_obj:
logger.debug("Replanning")
commons.bread = defaultdict(int)
planification_ = {}
if multiplicator == 0:
multiplicator = 1
servers = prefs.JSONloadFromDisk("channels.json")
for server_ in list(servers.keys()):
server = bot.get_server(str(server_))
if not server:
logger.debug("Non-existant server: " + str(server_))
servers.pop(server_)
scores.delServerPlayers(sid=server_)
elif not "channels" in servers[server.id]:
await comm.logwithinfos(server.default_channel, log_str="Server not configured: " + server.id)
try:
await bot.send_message(server, "The bot is not configured properly, please check the config or contact Eyesofcreeper#4758 | https://discord.gg/2BksEkV")
await comm.logwithinfos(server.default_channel, log_str="Unconfigured message sent...")
except:
await comm.logwithinfos(server.default_channel, log_str="Error sending the unconfigured message to the default channel on the server.")
else:
for channel_ in servers[server.id]["channels"]:
channel = server.get_channel(str(channel_))
if channel:
permissions = channel.permissions_for(server.me)
if permissions.read_messages and permissions.send_messages:
# logger.debug("Adding channel: {id} ({ducks_per_day} c/j)".format(**{
# "id" : channel.id,
# "ducks_per_day": prefs.getPref(server, "ducks_per_day")
# }))
planification_[channel] = round(prefs.getPref(server, "ducks_per_day") * multiplicator)
else:
await comm.logwithinfos(channel, log_str="Error adding channel to planification: no read/write permissions!")
else:
pass
commons.ducks_planned = planification_ # {"channel":[time objects]}
prefs.JSONsaveToDisk(servers, "channels.json")
else:
commons.bread[channel_obj] = 0
permissions = channel_obj.permissions_for(channel_obj.server.me)
if permissions.read_messages and permissions.send_messages:
pass
else:
await comm.logwithinfos(channel_obj, log_str="Error adding channel to planification: no read/write permissions!")
commons.ducks_planned[channel_obj] = round(prefs.getPref(channel_obj.server, "ducks_per_day") * multiplicator)
评论列表
文章目录