-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ce7cbc
commit b5444e9
Showing
13 changed files
with
246 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
], | ||
"deno.enable": true, | ||
"editor.inlayHints.enabled": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Command } from "./mod.ts"; | ||
import { AppMention, slack } from "../lib/slack.ts"; | ||
import { convertEventsToDisplayString, getEvents } from "../lib/meetup.ts"; | ||
|
||
export const eventsCommand: Command<AppMention> = { | ||
matcher: (msg) => /^<@.+> events$/.test(msg), | ||
handler: async (event) => { | ||
const events = await getEvents(); | ||
const text = convertEventsToDisplayString(events); | ||
await slack.chat.postMessage({ | ||
channel: event.channel, | ||
text: text, | ||
}); | ||
}, | ||
name: "events", | ||
helpText: "lists upcoming events within the next week", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Command, commands } from "./mod.ts"; | ||
import { AppMention, slack } from "../lib/slack.ts"; | ||
|
||
export const helpCommand: Command<AppMention> = { | ||
matcher: (msg) => /^<@.+> help$/.test(msg), | ||
handler: async (event) => { | ||
const text = commands.map((command) => | ||
`${command.name} - ${command.helpText}` | ||
).join("\n"); | ||
|
||
await slack.chat.postMessage({ | ||
channel: event.channel, | ||
text: text, | ||
}); | ||
}, | ||
name: "help", | ||
helpText: "lists commands", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
import { eventsCommand } from "./events.ts"; | ||
import { helpCommand } from "./help.ts"; | ||
import { jobsCommand } from "./jobs.ts"; | ||
import { pingCommand } from "./ping.ts"; | ||
import { questionCommand } from "./question.ts"; | ||
|
||
export const commands = [pingCommand, jobsCommand]; | ||
export const commands = [ | ||
pingCommand, | ||
jobsCommand, | ||
helpCommand, | ||
eventsCommand, | ||
questionCommand, | ||
]; | ||
|
||
export interface Command<TSlackEvent> { | ||
matcher: (msg: string) => boolean; | ||
handler: (event: TSlackEvent) => Promise<void>; | ||
name: string; | ||
helpText: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import { Command } from "./mod.ts"; | ||
import { AppMention, slack } from "../lib/slack.ts"; | ||
import { AppMention, respondInThread, slack } from "../lib/slack.ts"; | ||
|
||
export const pingCommand: Command<AppMention> = { | ||
matcher: (msg) => /^<@.+> ping$/.test(msg), | ||
handler: async (event) => { | ||
await slack.chat.postMessage({ | ||
channel: event.channel, | ||
text: "pong", | ||
}); | ||
// const response = await slack.chat.postMessage({ | ||
// channel: event.channel, | ||
// text: "pong", | ||
// thread_ts:event.thread_ts || event.ts, | ||
// }); | ||
|
||
const response = await respondInThread(event, "pong"); | ||
|
||
console.log(response); | ||
}, | ||
name: "ping", | ||
helpText: "pong", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Command } from "./mod.ts"; | ||
import { AppMention, slack } from "../lib/slack.ts"; | ||
|
||
export const questionCommand: Command<AppMention> = { | ||
matcher: (msg) => /^<@.+> question$/.test(msg), | ||
handler: async (event) => { | ||
//From chat-gpt | ||
const questions = [ | ||
"What project are you currently working on that excites you the most?", | ||
"How did you get started in software development?", | ||
"What's your favorite programming language, and why?", | ||
"What’s the most interesting problem you’ve solved recently?", | ||
"Which tool or framework can’t you live without?", | ||
"Do you prefer working on frontend, backend, or full-stack development?", | ||
"What’s the best piece of coding advice you’ve ever received?", | ||
"What’s a tech challenge you’re currently facing?", | ||
"Which open-source projects do you contribute to, or which ones do you follow?", | ||
"What’s the most exciting new technology or trend in software development you’re keeping an eye on?", | ||
"Do you have a favorite coding resource or blog you’d recommend to others?", | ||
"How do you stay motivated during tough coding sessions?", | ||
"What’s a non-tech hobby that helps you unwind from coding?", | ||
"What’s your favorite code editor or IDE, and why?", | ||
"What’s the most interesting or unusual place you’ve ever coded from?", | ||
]; | ||
|
||
const text = questions[Math.floor(Math.random() * questions.length)]; | ||
|
||
await slack.chat.postMessage({ | ||
channel: event.channel, | ||
text: text, | ||
}); | ||
}, | ||
name: "question", | ||
helpText: "Chooses from a list of questions to ask as conversation starters", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
interface Event { | ||
date: Date; | ||
dateTime: string; | ||
title: string; | ||
shortUrl: string; | ||
} | ||
|
||
export async function getEventsInTheNextWeek(): Promise<Event[]> { | ||
const gql = ` | ||
query { | ||
groupByUrlname(urlname: "devICT") { | ||
upcomingEvents(input:{first: 10, reverse: true}) { | ||
edges { | ||
node { | ||
title | ||
dateTime | ||
shortUrl | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`.trim(); | ||
|
||
const resp = await fetch("https://api.meetup.com/gql", { | ||
method: "POST", | ||
body: JSON.stringify({ query: gql }), | ||
}); | ||
|
||
if (!resp.ok) { | ||
throw new Error(`meetup request failed: ${await resp.text()}`); | ||
} | ||
|
||
const respData = await resp.json(); | ||
|
||
console.log(respData.data.groupByUrlname.upcomingEvents.edges); | ||
|
||
const events: Event[] = respData.data.groupByUrlname.upcomingEvents.edges.map( | ||
(e) => ({ | ||
...e.node, | ||
date: new Date(e.node.dateTime), | ||
}), | ||
); | ||
|
||
console.log(events); | ||
|
||
const eventsInTheNextWeek = events.filter((e) => { | ||
const now = new Date(); | ||
const endOfNextWeek = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000); | ||
return e.date > now && e.date < endOfNextWeek; | ||
}); | ||
|
||
return eventsInTheNextWeek; | ||
} | ||
|
||
export function convertEventsToDisplayString(events: Event[]): string { | ||
const weekday = (date: Date) => | ||
date.toLocaleString("en-us", { | ||
weekday: "long", | ||
timeZone: "America/Chicago", | ||
}); | ||
const timeStr = (date: Date) => | ||
date.toLocaleString("en-us", { | ||
hour: "2-digit", | ||
minute: "2-digit", | ||
timeZone: "America/Chicago", | ||
}); | ||
|
||
const eventLines = events.map(({ date, title, shortUrl }) => | ||
` | ||
:boom: *<${shortUrl}|${title}>*: ${weekday(date)} (${timeStr(date)}) | ||
`.trim() | ||
).join("\r\n"); | ||
|
||
const msg = | ||
`*<https://meetup.com/devict|Events happening this week>*\r\n\r\n${eventLines}`; | ||
|
||
return msg; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
b5444e9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failed to deploy: