Commit 7b189ef6 authored by IS1_4M's avatar IS1_4M
Browse files

fixed bug in weeklymeeting

:# Please enter the commit message for your changes. Lines starting
parent 3df4680d
......@@ -18,7 +18,11 @@ from restrictedchannel import RestrictChan, RestrictChanSuite
from AbstractChannel import AbstractChanSuite
from AdminChannel import AdminChanSuite
from SOCChannel import SOCChannelSuite
from handles import User, ECMember, ECStudent, ECFaculty, Organizer, Convener, Admin, SuperAdmin, student_role_name, faculty_role_name, general_user_role_names
from handles import User, ECMember, ECStudent, ECFaculty, Organizer,\
Convener, Admin, SuperAdmin, student_role_name, faculty_role_name, \
general_user_role_names, account_password, bot_token, \
send_account_email, domain_dest, auth_channel,\
MIN_BETWEEN_TASK_EXECUTIONS
from rssfeedtest import get_today_at_earlham
from Response_Handling import handle_response_codes
import json
......@@ -36,14 +40,7 @@ def is_auth(channel, auth_channel_name):
# if channel.name == auth_channel_name:
# return channel
#return False
auth_channel = 'auth'
domain_dest = '@earlham.edu'
send_account_email='earlhamhackerscontrol@gmail.com'
with open('../../../ECHackersBotCreds/credentials.json') as file:
credentials = json.load(file)
account_password = credentials['email_password']
clubs = []
users = []
......@@ -57,9 +54,9 @@ async def make_new_member(member):
return new_member
@tasks.loop(minutes=15)
@tasks.loop(minutes=MIN_BETWEEN_TASK_EXECUTIONS)
async def do_scheduled_tasks():
print('started processing tasks')
#print('started processing tasks')
for guild in client.guilds:
clis = AbstractChanSuite.get_all_clis(guild)
try:
......@@ -79,6 +76,7 @@ async def wait_until_multiple_of_15_min():
print('Started before loop of server task scheduling service')
now = datetime.now()
future = datetime(now.year, now.month, now.day, now.hour + ((now.minute//15 + 1)==4), ((now.minute//15 + 1) * 15)%60, 0, 0)
#future = datetime(now.year, now.month, now.day, now.hour + (not (now.minute + 1) % 60), ((now.minute) + 1)%60, 0,0)
print('waiting to start server task scheduling service (s):',(future - now).seconds , 'or in minutes: ', (future-now).seconds//60)
await sleep((future - now).seconds)
#print('sleeping 10 seconds')
......@@ -291,4 +289,4 @@ async def on_message(message):
# We NEED to be able to host remote events. Convocation, Speaker events, and more
do_scheduled_tasks.start()
update_today_at_schools.start()
client.run(credentials['bot_token'])
client.run(bot_token)
......@@ -7,7 +7,8 @@ Created on Sat Sep 5 14:08:39 2020
import discord
from AbstractChannel import AbstractChanSuite, AbstractChannel
from datetime import datetime
from datetime import datetime, timedelta
from handles import MIN_BETWEEN_TASK_EXECUTIONS, PROCESSING_TIME_PADDING
def get_member_by_discord_name(guild, discord_name):
for member in guild.members:
if member.name + "#" + member.discriminator == discord_name:
......@@ -388,7 +389,9 @@ class ClubSuite(AbstractChanSuite):
if message_parts[4] == now.strftime('%A') + 's':
#if 1 == 1:
hour, minute = message_parts[6].split(':')
if (datetime(now.year, now.month,now.day, int(hour), int(minute)) - now).seconds // 60 <= 15:
#print('sec_diff is: ', (datetime(now.year, now.month,now.day, int(hour), int(minute)) - now + timedelta(seconds=PROCESSING_TIME_PADDING)).seconds, 'delta_int is:', MIN_BETWEEN_TASK_EXECUTIONS*60)
#print('timedelta is: ',(datetime(now.year, now.month,now.day, int(hour), int(minute)) - now + timedelta(seconds=PROCESSING_TIME_PADDING)).seconds)
if (datetime(now.year, now.month,now.day, int(hour), int(minute)) - now + timedelta(seconds=PROCESSING_TIME_PADDING)).seconds< MIN_BETWEEN_TASK_EXECUTIONS*60:
''' extract content'''
content_start = 0
content_end = 0
......@@ -406,16 +409,18 @@ class ClubSuite(AbstractChanSuite):
if textchannel.name in pin.content:
await textchannel.send(content) # Also do one for day before,
elif pin.content.startswith('MESSAGE SCHEDULED for '):
print('invoked message scheduling')
message_parts = pin.content.split(' ')
now = datetime.now()
month,day,year = message_parts[3].split('/')
print(month,day,year)
print('now:', now.month, now.day, now.year)
#print(month,day,year)
#print('now:', now.month, now.day, now.year)
if now.day == int(day) and now.month == int(month) and now.year == int(year):
hour, minute = message_parts[5].split(':')
print(hour, minute)
min_diff = (datetime(now.year, now.month,now.day, int(hour), int(minute)) - now).seconds // 60
if -5 <= min_diff <= 15:
#print(hour, minute)
sec_diff = (datetime(now.year, now.month,now.day, int(hour), int(minute)) - now + timedelta(seconds= PROCESSING_TIME_PADDING)).seconds
#print('minutes difference is: ', min_diff)
if -1*MIN_BETWEEN_TASK_EXECUTIONS//3 *60 <= sec_diff < MIN_BETWEEN_TASK_EXECUTIONS * 60:
for textchannel in cli.guild.get_channel(cli.category_id).text_channels:
if textchannel.name == message_parts[-1]:
await textchannel.send(' '.join(message_parts[6:-2])) # Also do one for day before
......
......@@ -10,17 +10,22 @@ from datetime import datetime
from random import random
import json
with open('../../../ECHackersBotCreds/credentials.json') as file:
DEV_MODE = False
with open('../../../ECHackersBotCreds/credentials' + ('_test_bot.json' if DEV_MODE else '.json')) as file:
credentials = json.load(file)
auth_channel = 'auth'
domain_dest = '@earlham.edu'
send_account_email='earlhamhackerscontrol@gmail.com'
account_password = credentials['email_password']
bot_token = credentials['bot_token']
student_role_name = 'ECStudent'
faculty_role_name = 'ECFaculty'
general_user_role_names = [student_role_name, faculty_role_name]
MIN_BETWEEN_TASK_EXECUTIONS = 15
PROCESSING_TIME_PADDING = 30
clubs = []
users = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment