recurring events, limits to lengths
This commit is contained in:
parent
a3854ced0f
commit
1ba5e3c9f0
@ -103,10 +103,20 @@ function tellEvent(eventData: Event, msg: IMessage, countdown = true): void {
|
||||
tstamp = 'is over :(';
|
||||
}
|
||||
|
||||
let name = eventData.name;
|
||||
if (name.length > 64) {
|
||||
name = name.substr(0, 64) + '...';
|
||||
}
|
||||
|
||||
let description = eventData.description;
|
||||
if (description.length > 120) {
|
||||
description = description.substr(0, 120) + '...';
|
||||
}
|
||||
|
||||
keys.push(['field', 'Event', { type: 'title', color: 'green' }]);
|
||||
keys.push(['field', eventData.name, { color: startColor }]);
|
||||
keys.push(['field', name, { color: startColor }]);
|
||||
keys.push(['bold', tstamp]);
|
||||
keys.push(['field', eventData.description || '', { type: 'content' }]);
|
||||
keys.push(['field', description || '', { type: 'content' }]);
|
||||
|
||||
msg.resolve(keys);
|
||||
}
|
||||
@ -133,6 +143,33 @@ async function fetchCalendars(interval: number): Promise<void> {
|
||||
const start = Math.floor(new Date(data.start).getTime() / 1000);
|
||||
const end = Math.floor(new Date(data.end).getTime() / 1000);
|
||||
|
||||
// Recurring events handling
|
||||
if ('rrule' in data) {
|
||||
const rrule = (data as any).rrule as any;
|
||||
const recurring = rrule.between(new Date(),
|
||||
new Date(Date.now() + cfg.timeFrame * 1000));
|
||||
const originalDuration = end - start;
|
||||
for (const date of recurring) {
|
||||
const newStart = Math.floor(new Date(date).getTime() / 1000);
|
||||
const newEnd = newStart + originalDuration;
|
||||
if (newStart > nts() + cfg.timeFrame || newEnd < nts()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
memcache.push({
|
||||
id: key,
|
||||
name: (data as any).summary,
|
||||
start: newStart,
|
||||
end: newEnd,
|
||||
from: cfg,
|
||||
description: (data as any).description || '',
|
||||
});
|
||||
|
||||
events++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip events that are over and start beyond the time frame
|
||||
if (start > nts() + cfg.timeFrame || end < nts()) {
|
||||
continue;
|
||||
@ -191,7 +228,8 @@ class CalendarPlugin extends Plugin {
|
||||
}
|
||||
|
||||
events = events.filter((ev: Event) =>
|
||||
ev.start < nts() + ev.from.timeFrame && ev.end > nts());
|
||||
ev.start < nts() + ev.from.timeFrame && ev.end > nts())
|
||||
.slice(0, 8);
|
||||
|
||||
if (!events.length) {
|
||||
msg.resolve('Events in %s: None currently scheduled.', msg.target?.name);
|
||||
@ -236,15 +274,15 @@ class CalendarPlugin extends Plugin {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ev.name.toLowerCase().match(query) != null;
|
||||
});
|
||||
return ev.name.toLowerCase().match(query.toLowerCase()) != null;
|
||||
}).slice(0, 8);
|
||||
|
||||
if (!events.length) {
|
||||
msg.resolve('No events match "%s".', query);
|
||||
return true;
|
||||
} else if (events.length > 1) {
|
||||
msg.resolve('Multiple events match "%s":', query);
|
||||
return true;
|
||||
msg.resolve('Multiple events match "%s"! Here\'s the first one:', query);
|
||||
events = events.sort(sortStartTime);
|
||||
}
|
||||
|
||||
tellEvent(events[0], msg, countdown);
|
||||
|
Loading…
Reference in New Issue
Block a user