🏷️ Add return types
This commit is contained in:
@@ -13,9 +13,11 @@ export {
|
|||||||
say
|
say
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: clean/refactor code
|
||||||
|
|
||||||
const LOG_PREFIX = "[ChatClient] ";
|
const LOG_PREFIX = "[ChatClient] ";
|
||||||
|
|
||||||
async function connect(channels: Array<any>) {
|
async function connect(channels: Array<any>): Promise<void> {
|
||||||
const authProvider = await getAuthProvider();
|
const authProvider = await getAuthProvider();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -43,13 +45,13 @@ async function connect(channels: Array<any>) {
|
|||||||
await chatClient.connect();
|
await chatClient.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onConnect() {
|
async function onConnect(): Promise<void> {
|
||||||
console.log(`${LOG_PREFIX}Connected`);
|
console.log(`${LOG_PREFIX}Connected`);
|
||||||
|
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleClientAction(action: any) {
|
async function handleClientAction(action: any): Promise<void> {
|
||||||
if (action.channel && !isNaN(action.channel)) {
|
if (action.channel && !isNaN(action.channel)) {
|
||||||
action.channel = await getUsernameFromId(parseInt(action.channel));
|
action.channel = await getUsernameFromId(parseInt(action.channel));
|
||||||
}
|
}
|
||||||
@@ -84,7 +86,7 @@ async function handleClientAction(action: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send a chat message
|
// send a chat message
|
||||||
async function say(channel: string, message: string) {
|
async function say(channel: string, message: string): Promise<void> {
|
||||||
await chatClient.say(channel, message);
|
await chatClient.say(channel, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +96,7 @@ async function timeout(
|
|||||||
username: string,
|
username: string,
|
||||||
time?: number,
|
time?: number,
|
||||||
reason?: string
|
reason?: string
|
||||||
) {
|
): Promise<void> {
|
||||||
if (!time) {
|
if (!time) {
|
||||||
time = 60;
|
time = 60;
|
||||||
}
|
}
|
||||||
@@ -111,7 +113,7 @@ async function timeout(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// adds a user to vips
|
// adds a user to vips
|
||||||
async function addVip(channel: string, username: string, message?: string) {
|
async function addVip(channel: string, username: string, message?: string): Promise<void> {
|
||||||
if (!message) {
|
if (!message) {
|
||||||
message = `Otorgado VIP a @${username}.`;
|
message = `Otorgado VIP a @${username}.`;
|
||||||
}
|
}
|
||||||
@@ -121,7 +123,7 @@ async function addVip(channel: string, username: string, message?: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// removes a user from vips
|
// removes a user from vips
|
||||||
async function removeVip(channel: string, username: string, message?: string) {
|
async function removeVip(channel: string, username: string, message?: string): Promise<void> {
|
||||||
if (!message) {
|
if (!message) {
|
||||||
message = `VIP de @${username} eliminado.`;
|
message = `VIP de @${username} eliminado.`;
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,8 @@ export {
|
|||||||
registerUserListener
|
registerUserListener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: clean/refactor code
|
||||||
|
|
||||||
const LOG_PREFIX = "[PubSub] ";
|
const LOG_PREFIX = "[PubSub] ";
|
||||||
|
|
||||||
async function registerUserListener(user: UserIdResolvable) {
|
async function registerUserListener(user: UserIdResolvable) {
|
||||||
@@ -100,7 +102,7 @@ async function stealVip(msg: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// adds a user to vips
|
// adds a user to vips
|
||||||
async function addVip(channel: string, username: string, message?: string) {
|
async function addVip(channel: string, username: string, message?: string): Promise<void> {
|
||||||
if (!message) {
|
if (!message) {
|
||||||
message = `Otorgado VIP a @${username}.`;
|
message = `Otorgado VIP a @${username}.`;
|
||||||
}
|
}
|
||||||
@@ -109,7 +111,7 @@ async function addVip(channel: string, username: string, message?: string) {
|
|||||||
say(channel, message);
|
say(channel, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function hasVip(channel: string, username: string) {
|
async function hasVip(channel: string, username: string): Promise<boolean> {
|
||||||
if (!username) {
|
if (!username) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -119,7 +121,7 @@ async function hasVip(channel: string, username: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// removes a user from vips
|
// removes a user from vips
|
||||||
async function removeVip(channel: string, username: string, message?: string) {
|
async function removeVip(channel: string, username: string, message?: string): Promise<void> {
|
||||||
if (!message) {
|
if (!message) {
|
||||||
message = `Se ha acabado el chollo, VIP de @${username} eliminado.`;
|
message = `Se ha acabado el chollo, VIP de @${username} eliminado.`;
|
||||||
}
|
}
|
||||||
|
@@ -17,15 +17,19 @@ let checkingScheduled = false;
|
|||||||
let scheduledActionsInterval: NodeJS.Timeout;
|
let scheduledActionsInterval: NodeJS.Timeout;
|
||||||
let saveScheduledActionsTimeout: NodeJS.Timeout | null;
|
let saveScheduledActionsTimeout: NodeJS.Timeout | null;
|
||||||
|
|
||||||
async function start() {
|
// *Check this, not working
|
||||||
// *Check this, not working
|
async function start(): Promise<void> {
|
||||||
if (!scheduledActionsInterval) {
|
if (scheduledActionsInterval) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let savedActions = [];
|
let savedActions = [];
|
||||||
try {
|
try {
|
||||||
savedActions = JSON.parse((await fs.readFile(SCHEDULED_FILE)).toString());
|
savedActions = JSON.parse((await fs.readFile(SCHEDULED_FILE)).toString());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// probably file does not exist
|
// probably file does not exist
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduledActions.push.apply(scheduledActions, savedActions);
|
scheduledActions.push.apply(scheduledActions, savedActions);
|
||||||
scheduledActions.sort((a, b) => a.scheduledAt - b.scheduledAt);
|
scheduledActions.sort((a, b) => a.scheduledAt - b.scheduledAt);
|
||||||
|
|
||||||
@@ -34,8 +38,11 @@ async function start() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkScheduledActions() {
|
async function checkScheduledActions(): Promise<void> {
|
||||||
if (checkingScheduled) return;
|
if (checkingScheduled) {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
checkingScheduled = true;
|
checkingScheduled = true;
|
||||||
|
|
||||||
let hasToSave = false;
|
let hasToSave = false;
|
||||||
@@ -60,7 +67,7 @@ async function checkScheduledActions() {
|
|||||||
checkingScheduled = false;
|
checkingScheduled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveScheduledActions() {
|
function saveScheduledActions(): void {
|
||||||
if (saveScheduledActionsTimeout) {
|
if (saveScheduledActionsTimeout) {
|
||||||
clearTimeout(saveScheduledActionsTimeout);
|
clearTimeout(saveScheduledActionsTimeout);
|
||||||
saveScheduledActionsTimeout = null;
|
saveScheduledActionsTimeout = null;
|
||||||
|
@@ -40,7 +40,7 @@ async function saveTokenData(tokenData: TokenData): Promise<void> {
|
|||||||
console.log(`${LOG_PREFIX}Token data saved`);
|
console.log(`${LOG_PREFIX}Token data saved`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkTokenData(tokenData: TokenData) {
|
function checkTokenData(tokenData: TokenData): void {
|
||||||
if (
|
if (
|
||||||
!tokenData.access_token ||
|
!tokenData.access_token ||
|
||||||
!tokenData.refresh_token
|
!tokenData.refresh_token
|
||||||
|
Reference in New Issue
Block a user