Skip to content

Commit 92485f8

Browse files
committed
Finish the polling feature :3
1 parent 6b58a21 commit 92485f8

File tree

8 files changed

+4843
-0
lines changed

8 files changed

+4843
-0
lines changed

dist/main.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
return new (P || (P = Promise))(function (resolve, reject) {
4+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7+
step((generator = generator.apply(thisArg, _arguments || [])).next());
8+
});
9+
};
10+
Object.defineProperty(exports, "__esModule", { value: true });
11+
const discord_js_1 = require("discord.js");
12+
const Canister = new discord_js_1.Client();
13+
const THUMBS_UP = "👍";
14+
const THUMBS_DOWN = "👎";
15+
Canister.on("ready", () => {
16+
console.log("I am ready!");
17+
});
18+
function allowThumbsOnly(reaction, user) {
19+
return reaction.emoji.name === THUMBS_UP || reaction.emoji.name === THUMBS_DOWN;
20+
}
21+
Canister.on("message", (message) => __awaiter(this, void 0, void 0, function* () {
22+
const matched = message.content.match(/^\/poll\s+?(.+)\s+?(\d)/i);
23+
if (matched && matched.index !== -1) {
24+
const pollQuestion = matched[1];
25+
const pollTimeout = parseInt(matched[2], 10);
26+
const embedOptions = {
27+
title: pollQuestion,
28+
};
29+
const embed = new discord_js_1.RichEmbed(embedOptions);
30+
try {
31+
const botMessage = yield message.channel.send("@everyone:", embed);
32+
const yesReaction = yield botMessage.react(THUMBS_UP);
33+
const noReaction = yield botMessage.react(THUMBS_DOWN);
34+
if (message.deletable) {
35+
message.delete();
36+
}
37+
Canister.on("messageReactionAdd", (reaction, { username }) => __awaiter(this, void 0, void 0, function* () {
38+
if (reaction.message.id === botMessage.id) {
39+
console.log(`${username} has voted! total: ${reaction.count}`);
40+
}
41+
}));
42+
setTimeout(() => {
43+
// botMessage.delete();
44+
}, pollTimeout * 1000);
45+
}
46+
catch (err) {
47+
console.error(err);
48+
}
49+
}
50+
}));
51+
Canister.login("NDAzMDQwMjk0MDMzMTYyMjQw.DUYDhA.7A1x8FSeqCi_2A06LVQ9hYWbkSU");

gulpfile.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const gulp = require('gulp');
2+
const ts = require("gulp-typescript");
3+
const tslint = require("gulp-tslint");
4+
const { resolve } = require("path");
5+
6+
const tsProject = ts.createProject("tsconfig.json");
7+
8+
gulp.task("ts", () => (
9+
tsProject.src()
10+
.pipe(tsProject())
11+
.js.pipe(gulp.dest("dist"))
12+
));
13+
14+
gulp.task('tslint', () => (
15+
tsProject.src()
16+
.pipe(tslint({
17+
formatter: 'verbose'
18+
}))
19+
.pipe(tslint.report())
20+
));
21+
gulp.task('watch', () => (
22+
gulp.watch('src/**/*.ts', ['ts'])
23+
));
24+
25+
gulp.task("default", [ "ts"]);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy