Skip to content

Commit

Permalink
chore: stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mo9a7i committed Sep 24, 2023
1 parent a6a3ca1 commit 0772254
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# foursquare_bot

## 2.1.1

### Patch Changes

- chore: stuff

## 2.1.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "foursquare_bot",
"version": "2.1.0",
"version": "2.1.1",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
32 changes: 17 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,29 @@ const collection_name = 'foursqure';

async function handleAutoLike(user_id: string, autolikeConfig: any, fsq_instances: any) {
let interval: any = autolikeConfig.interval;
console.log(`07: Auto likes enabled with ${interval} (${cronstrue.toString(interval)})`);


async function like_unliked() {
console.log(Date(), `Running autolike for user ${user_id} with ${interval} (${cronstrue.toString(interval)})`);
console.log("07-01: ", Date(), `Running autolike for user ${user_id} with ${interval} (${cronstrue.toString(interval)})`);
const NUMBER_OF_CHECKINS_TO_LIKE = 20;
const request = await fsq_instances[user_id].likeUnliked(NUMBER_OF_CHECKINS_TO_LIKE);
console.log(`success: ${request.succeeded.length} failed: ${request.failed.length}`);
console.log(`07-02: Successfully liked: ${request.succeeded.length}, failed: ${request.failed.length}`);
}

let task = scheduleTask(interval, like_unliked);
return task;
}

async function handleAutoCheckin(user_id: string, autoCheckin: any, fsq_instances: any) {
console.log(`07: venues checkins enabled`);
const venues = Object.entries(autoCheckin.venues);
console.log(`08: found ${venues.length} venue`);
console.log(`08-01: found ${venues.length} venue`);
let tasks: any = [];

venues.forEach(([venue_id, venue]: any) => {
venue.intervals.forEach((interval: any) => {
console.log(`09: Setting user ${user_id} check in for ${chalk.green.bold(venue.name)} at the set interval ${chalk.underline(interval.interval)} (${cronstrue.toString(interval.interval)})`);
console.log(`08-02: Setting user ${user_id} check in for ${chalk.green.bold(venue.name)} at the set interval ${chalk.underline(interval.interval)} (${cronstrue.toString(interval.interval)})`);

let task = scheduleTask(interval.interval, async () => {
console.log(Date(), `Checking in user ${user_id} on ${venue_id}`);
console.log("08-03: ", Date(), `Checking in user ${user_id} on ${venue_id}`);
await fsq_instances[user_id].checkIn(venue_id);
});
tasks.push(task);
Expand All @@ -48,17 +46,17 @@ async function handleAutoCheckin(user_id: string, autoCheckin: any, fsq_instance
}

async function handleAutoAddTrending(user_id: string, autoAddTrending: any, fsq_instances: any) {
console.log(`10: Auto Add Trending enabled`);
const locations = Object.entries(autoAddTrending?.locations);
console.log(`11: found ${locations.length} locations`);
console.log(`09-01: found ${locations.length} locations`);
let tasks: any = [];

locations?.forEach(([location_name, location]: any) => {
console.log(`12: setting user ${user_id} auto checkin and add for ${location_name} at the set interval ${location.interval} (${cronstrue.toString(location.interval)})`);
console.log(`09-02: setting user ${user_id} auto checkin and add for ${location_name} at the set interval ${location.interval} (${cronstrue.toString(location.interval)})`);

let task = scheduleTask(location.interval, async () => {
console.log(Date(), `auto adding user ${user_id} on ${location_name}`);
await fsq_instances[user_id].autoAddTrending(location_name, location.venues_limit);
console.log("09-03: ", Date(), `auto adding user ${user_id} on ${location_name}`);
const auto_trending_result = await fsq_instances[user_id].autoAddTrending(location_name, location.venues_limit);
console.log(`09-04:`, auto_trending_result);
});
tasks.push(task);
});
Expand Down Expand Up @@ -121,6 +119,7 @@ async function run() {
const autolikeConfig = user_configs.settings?.autolike;

if (autolikeConfig?.enabled) {
console.log(`07: Auto likes enabled with ${autolikeConfig.interval} (${cronstrue.toString(autolikeConfig.interval)})`);
let task = await handleAutoLike(user_id, autolikeConfig, fsq_instances);
tasks.push(task);
}
Expand All @@ -129,6 +128,7 @@ async function run() {
const autoCheckin = user_configs.settings?.checkins;

if (autoCheckin?.enabled) {
console.log(`08: Auto checkins enabled`);
let checkinTasks = await handleAutoCheckin(user_id, autoCheckin, fsq_instances);
tasks = [...tasks, ...checkinTasks];
}
Expand All @@ -137,6 +137,7 @@ async function run() {
const autoAddTrending = user_configs.settings?.autoaddtrending;

if (autoAddTrending?.enabled) {
console.log(`09: Auto add trending enabled`);
let trendingTasks = await handleAutoAddTrending(user_id, autoAddTrending, fsq_instances);
tasks = [...tasks, ...trendingTasks];
}
Expand All @@ -147,12 +148,13 @@ async function run() {
}
}
catch (error) {
console.error(`Error checking token validity:`, error);
console.error(`06: Error checking token validity:`, error);
}
}

for (const task of tasks) {
console.log('Starting task');
// print task index
console.log(`10: Starting task ${chalk.bold(tasks.indexOf(task))}`);
task.start();
}
}
Expand Down

0 comments on commit 0772254

Please sign in to comment.