Skip to content

Commit

Permalink
refactor import statement for "bot" & use chatMembers' getChatMember()
Browse files Browse the repository at this point in the history
  • Loading branch information
ryukaizen committed Apr 6, 2024
1 parent abd8f67 commit 868c90a
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 23 deletions.
24 changes: 12 additions & 12 deletions src/helpers/helper_func.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function samePersonCallbackOnly(handler: any) {
// for reply_to_message
export async function checkElevatedUser(ctx: any) {
// fetch user status
let user = await ctx.api.getChatMember(ctx.chat.id, ctx.message.reply_to_message.from.id)
let user = await ctx.chatMembers.getChatMember(ctx.chat.id, ctx.message.reply_to_message.from.id)
if (ctx.message.reply_to_message.from.id == constants.OWNER_ID || constants.SUPERUSERS.includes(ctx.message.reply_to_message.from.id) == true || user.status == "creator" || user.status == "administrator") {
return true;
}
Expand All @@ -87,7 +87,7 @@ export async function checkElevatedUser(ctx: any) {

// for general stuff
export async function checkElevatedUserFrom(ctx: any, user_info: any) {
let user = await ctx.api.getChatMember(ctx.chat.id, user_info.user.id)
let user = await ctx.chatMembers.getChatMember(ctx.chat.id, user_info.user.id)
if (user_info.user.id == constants.OWNER_ID || constants.SUPERUSERS.includes(user_info.user.id) == true || user.status == "creator" || user.status == "administrator") {
return true;
}
Expand All @@ -104,7 +104,7 @@ export async function userInfo(ctx: any) {

// future use maybe
export async function isUserInChat(ctx: any, chat_id: string, user_id: number) {
let user = await ctx.api.getChatMember(chat_id, user_id);
let user = await ctx.chatMembers.getChatMember(chat_id, user_id);
if (user.status == "member" || user.status == "restricted" || user.status == "creator" || user.status == "administrator") {
return true;
}
Expand All @@ -115,7 +115,7 @@ export async function isUserInChat(ctx: any, chat_id: string, user_id: number) {
}

export async function isUserRestricted(ctx: any, chat_id: string, user_id: number) {
let user = await ctx.api.getChatMember(chat_id, user_id);
let user = await ctx.chatMembers.getChatMember(chat_id, user_id);
if (user.status == "restricted") {
return true;
}
Expand All @@ -125,7 +125,7 @@ export async function isUserRestricted(ctx: any, chat_id: string, user_id: numbe
}

export async function isUserBanned(ctx: any, chat_id: string, user_id: number) {
let user = await ctx.api.getChatMember(chat_id, user_id);
let user = await ctx.chatMembers.getChatMember(chat_id, user_id);
if (user.status == "kicked") {
return true;
}
Expand Down Expand Up @@ -268,7 +268,7 @@ export function botCanRestrictUsers(hander: any) {
return async (ctx: any) => {
let bot_id = ctx.me.id;
let chat_id = ctx.chat.id;
let bot_info = await ctx.api.getChatMember(chat_id, bot_id);
let bot_info = ctx.chatMembers.getChatMember(chat_id, bot_id);
if (bot_info.status == "administrator") {
if (bot_info.can_restrict_members == true) {
await hander(ctx);
Expand All @@ -287,7 +287,7 @@ export function botCanRestrictUsersCallback(hander: any) {
return async (ctx: any) => {
let bot_id = ctx.me.id;
let chat_id = ctx.chat.id;
let bot_info = await ctx.api.getChatMember(chat_id, bot_id);
let bot_info = await ctx.chatMembers.getChatMember(chat_id, bot_id);
if (bot_info.status == "administrator") {
if (bot_info.can_restrict_members == true) {
await hander(ctx);
Expand All @@ -306,7 +306,7 @@ export function botCanDeleteMessages(handler: any) {
return async (ctx: any) => {
let bot_id = ctx.me.id;
let chat_id = ctx.chat.id;
let bot_info = await ctx.api.getChatMember(chat_id, bot_id);
let bot_info = await ctx.chatMembers.getChatMember(chat_id, bot_id);
if (bot_info.status == "administrator") {
if (bot_info.can_delete_messages == true) {
await handler(ctx);
Expand All @@ -325,7 +325,7 @@ export function botCanPinMessages(handler: any) {
return async (ctx: any) => {
let bot_id = ctx.me.id;
let chat_id = ctx.chat.id;
let bot_info = await ctx.api.getChatMember(chat_id, bot_id);
let bot_info = await ctx.chatMembers.getChatMember(chat_id, bot_id);
if (bot_info.status == "administrator") {
if (bot_info.can_pin_messages == true) {
await handler(ctx);
Expand All @@ -344,7 +344,7 @@ export function botCanInviteUsers(handler: any) {
return async (ctx: any) => {
let bot_id = ctx.me.id;
let chat_id = ctx.chat.id;
let bot_info = await ctx.api.getChatMember(chat_id, bot_id);
let bot_info = await ctx.chatMembers.getChatMember(chat_id, bot_id);
if (bot_info.status == "administrator") {
if (bot_info.can_invite_users == true) {
await handler(ctx);
Expand All @@ -363,7 +363,7 @@ export function botCanPromoteMembers(handler: any) {
return async (ctx: any) => {
let bot_id = ctx.me.id;
let chat_id = ctx.chat.id;
let bot_info = await ctx.api.getChatMember(chat_id, bot_id);
let bot_info = await ctx.chatMembers.getChatMember(chat_id, bot_id);
if (bot_info.status == "administrator") {
if (bot_info.can_promote_members == true) {
await handler(ctx);
Expand All @@ -382,7 +382,7 @@ export function botCanChangeInfo(handler: any) {
return async (ctx: any) => {
let bot_id = ctx.me.id;
let chat_id = ctx.chat.id;
let bot_info = await ctx.api.getChatMember(chat_id, bot_id);
let bot_info = await ctx.chatMembers.getChatMember(chat_id, bot_id);
if (bot_info.status == "administrator") {
if (bot_info.can_change_info == true) {
await handler(ctx);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/admin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bot from "../bot";
import { bot } from "../bot";
import { InlineKeyboard } from "grammy";
import { logger, channel_log } from "../logger";
import {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/bans.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bot from "../bot";
import { bot } from "../bot";
import { logger, channel_log } from "../logger";
import { GrammyError, InlineKeyboard } from "grammy";
import {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/misc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bot from "../bot";
import { bot } from "../bot";
import os from 'os';
import si from 'systeminformation';
import { superusersOnly } from "../helpers/helper_func";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mutes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bot from "../bot";
import { bot } from "../bot";
import { logger, channel_log } from "../logger";
import { GrammyError, InlineKeyboard } from "grammy";
import {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/purges.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bot from "../bot";
import { bot } from "../bot";
import { logger, channel_log } from "../logger";
import {
adminCanDeleteMessages,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/reports.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bot from "../bot";
import { bot } from "../bot";
import { get_report_settings, set_report_settings } from "../database/reports_sql";
import { checkElevatedUser, elevatedUsersOnly } from "../helpers/helper_func";

Expand Down
2 changes: 1 addition & 1 deletion src/modules/rules.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bot from "../bot";
import { bot } from "../bot";
import constants from "../config";
import { get_rules, set_rules, reset_rules } from "../database/rules_sql";
import { InlineKeyboard } from "grammy";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bot from "../bot";
import { bot } from "../bot";

bot.chatType("supergroup" || "group").command("test", (async (ctx: any) => {
await ctx.api.sendMessage(ctx.chat?.id, "test")
Expand Down
2 changes: 1 addition & 1 deletion src/modules/users.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bot from "../bot";
import { bot } from "../bot";

bot.chatType("supergroup" || "group").command("id", (async (ctx: any) => {
let chat_id = ctx.chat.id;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/warns.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bot from "../bot";
import { bot } from "../bot";
import { logger, channel_log } from "../logger";
import { GrammyError, InlineKeyboard } from "grammy";
import {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/welcome.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bot from "../bot";
import { bot } from "../bot";
import constants from "../config";
import { channel_log } from "../logger";
import { InlineKeyboard } from "grammy";
Expand Down

0 comments on commit 868c90a

Please sign in to comment.