Add v1.0
This commit is contained in:
parent
6a5f642fb4
commit
48dffc112a
21 changed files with 1327 additions and 0 deletions
46
src/endpoints/public/unlurk.ts
Normal file
46
src/endpoints/public/unlurk.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import { ServerRoute } from "@hapi/hapi";
|
||||
import { formatMessage } from "@/utils";
|
||||
import boom from "@hapi/boom";
|
||||
import { db } from "@/main";
|
||||
import Joi from "joi";
|
||||
|
||||
const data: ServerRoute = {
|
||||
method: `GET`, path: `/{channel}/unlurk`,
|
||||
options: {
|
||||
auth: false,
|
||||
validate: {
|
||||
params: Joi.object({
|
||||
channel: Joi.string().alphanum(),
|
||||
}),
|
||||
query: Joi.object({
|
||||
user: Joi.string(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
async handler(request, h) {
|
||||
const { channel } = request.params;
|
||||
const { user } = request.query;
|
||||
|
||||
if (!db[channel]) {
|
||||
throw boom.notFound(`Invalid channel`);
|
||||
};
|
||||
|
||||
const messages = db[channel].messages;
|
||||
const messageId = db[channel].lurkers[user];
|
||||
const message = messages[messageId];
|
||||
let lurkMessage = message.unlurk[Math.floor(Math.random() * message.unlurk.length)];
|
||||
|
||||
delete db[channel].lurkers[user];
|
||||
|
||||
let twitchMessage = formatMessage(
|
||||
lurkMessage,
|
||||
{
|
||||
user,
|
||||
channel,
|
||||
}
|
||||
);
|
||||
|
||||
return h.response(twitchMessage).code(200);
|
||||
},
|
||||
};
|
||||
export default data;
|
||||
Loading…
Add table
Add a link
Reference in a new issue