-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
38 changed files
with
1,021 additions
and
460 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="index.js" type="NodeJSConfigurationType" nameIsGenerated="true" path-to-js-file="src/index.js" working-dir="$PROJECT_DIR$"> | ||
<method v="2"> | ||
<option name="TypeScript.Before.Run" enabled="true" FAIL_ON_ERROR="true" CONFIG_PATH="$PROJECT_DIR$/tsconfig.json" /> | ||
</method> | ||
</configuration> | ||
</component> |
Binary file not shown.
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,6 +1,6 @@ | ||
{ | ||
"sendActionMessage": true, | ||
"messagesReceived": 696, | ||
"messagesSent": 377, | ||
"testAnswer": true, | ||
"messagesReceived": 0, | ||
"messagesSent": 0 | ||
"sendActionMessage": true | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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,32 +1,141 @@ | ||
import {Command} from '../model/chat-command'; | ||
import {Command, Requirements} from '../model/chat-command'; | ||
import {Api} from '../api/api'; | ||
import {LoadManager} from '../api/load-manager'; | ||
import {MemoryCache} from '../database/memory-cache'; | ||
import {CacheStorage} from '../database/cache-storage'; | ||
import {MessageContext, MessageForwardsCollection} from 'vk-io'; | ||
import {TAG, TAG_ERROR} from '../index'; | ||
|
||
export class Admins extends Command { | ||
class AdminsList extends Command { | ||
regexp = /^\/admins/i; | ||
title = '/admins'; | ||
description = 'list of bot\'s admins'; | ||
|
||
async execute(context) { | ||
if (MemoryCache.admins.length == 0) { | ||
if (MemoryCache.isAdminsEmpty()) { | ||
await Api.sendMessage(context, 'Администраторов нет 😞'); | ||
return; | ||
} | ||
|
||
let text = 'Список администраторов:\n\n'; | ||
|
||
for (let i = 0; i < MemoryCache.admins.length; i++) { | ||
const id = MemoryCache.admins[i]; | ||
for (let i = 0; i < MemoryCache.adminsSize(); i++) { | ||
const id = MemoryCache.getAdminByIndex(i); | ||
|
||
let user = await CacheStorage.users.getSingle(id); | ||
let user = await MemoryCache.getUser(id); | ||
if (!user) user = await LoadManager.users.loadSingle(id); | ||
|
||
text += `❤ @id${id}(${user.firstName} ${user.lastName})\n`; | ||
} | ||
|
||
await Api.sendMessage(context, text, true); | ||
} | ||
} | ||
|
||
} | ||
class AdminAdd extends Command { | ||
|
||
regexp = /^\/addadmin/i; | ||
title = '/addAdmin'; | ||
description = 'adds bot\'s admin by id or replied message'; | ||
|
||
requirements = Requirements.Build().apply(true); | ||
|
||
async execute( | ||
context: MessageContext, | ||
params: string[], | ||
fwd?: MessageForwardsCollection, | ||
reply?: MessageContext | ||
): Promise<void> { | ||
|
||
let userId: number = null; | ||
|
||
if (reply) { | ||
userId = reply.senderId; | ||
} | ||
|
||
if (!userId) { | ||
if (context.text.includes(' ')) { | ||
const split = context.text.split(' '); | ||
try { | ||
userId = Number(split[1]); | ||
if (isNaN(userId)) userId = -1; | ||
} catch (e) { | ||
userId = -1; | ||
} | ||
} | ||
} | ||
|
||
if (!userId || userId < 0) { | ||
console.log(`${TAG_ERROR}: /addAdmin: wrong userId`); | ||
await Api.sendMessage(context, 'Неверный userId.', null, context.id); | ||
} else { | ||
console.log(`${TAG}: /addAdmin: added new admin: ${userId}`); | ||
|
||
let user = await MemoryCache.getUser(userId); | ||
if (!user) { | ||
await Api.sendMessage(context, 'секунду...'); | ||
user = await LoadManager.users.loadSingle(userId); | ||
} | ||
|
||
const message = `@id${user.id}(${user.firstName} ${user.lastName}) теперь администратор! 🥳`; | ||
|
||
const sendMessagePromise = Api.sendMessage(context, message, true); | ||
const storeUserPromise = CacheStorage.users.storeSingle(user); | ||
const storeAdminPromise = CacheStorage.admins.storeSingle(userId); | ||
|
||
await Promise.all([sendMessagePromise, storeUserPromise, storeAdminPromise]); | ||
} | ||
} | ||
|
||
} | ||
|
||
class AdminRemove extends Command { | ||
|
||
regexp = /^\/removeAdmin/i; | ||
title = '/removeAdmin'; | ||
name = '/removeAdmin'; | ||
description = 'removes bot\'s admin'; | ||
|
||
requirements = Requirements.Build().apply(true); | ||
|
||
async execute(context, params, fwd, reply): Promise<void> { | ||
|
||
let userId: number = null; | ||
|
||
if (reply) { | ||
userId = reply.senderId; | ||
} | ||
|
||
if (!userId) { | ||
if (context.text.includes(' ')) { | ||
try { | ||
userId = Number(context.text.split(' ')[1]); | ||
if (isNaN(userId)) userId = null; | ||
} catch (e) { | ||
userId = null; | ||
} | ||
} | ||
} | ||
|
||
if (!userId || userId < 0) { | ||
console.log(`${TAG_ERROR}: /removeAdmin: wrong userId`); | ||
await Api.sendMessage(context, 'Неверный userId.', null, context.id); | ||
} else { | ||
console.log(`${TAG}: /removeAdmin: removed admin: ${userId}`); | ||
await CacheStorage.admins.deleteSingle(userId); | ||
|
||
let user = await MemoryCache.getUser(userId); | ||
if (!user) { | ||
await Api.sendMessage(context, 'секунду...'); | ||
user = await LoadManager.users.loadSingle(userId); | ||
} | ||
|
||
const message = `@id${user.id}(${user.firstName} ${user.lastName}) больше не администратор 💔`; | ||
|
||
await Api.sendMessage(context, message, true); | ||
} | ||
} | ||
|
||
} | ||
|
||
export {AdminsList, AdminAdd, AdminRemove}; |
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
Oops, something went wrong.