Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@grammyjs/runner": "^2.0.3",
"@influxdata/influxdb-client": "^1.35.0",
"@polinetwork/auth-kit": "^1.1.0",
"@polinetwork/backend": "^1.4.0",
"@polinetwork/backend": "^4.0.0",
"@socket.io/devalue-parser": "^0.1.0",
"@t3-oss/env-core": "^0.13.4",
"@trpc/client": "^11.5.1",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/commands/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type CommandAccess = {
authorization: Decision
}

export const authorizeCommand: Authorize<Context, string, CommandAccess> = async ({ context, command }) => {
export const authorizeCommand: Authorize<Context, CommandAccess> = async ({ context, command }) => {
const { permissions } = command
if (!permissions?.requiredPermissions?.length) return { allowed: true, basis: null }
const from = context.from
Expand Down
2 changes: 1 addition & 1 deletion src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const adapter = new RedisFallbackAdapter<VersionedState<ConversationData>>({

type ConversationContext = TelemetryContextFlavor<CommandScopedContext>

export const commands = new ManagedCommands<string, Context, ConversationContext, CommandAccess>({
export const commands = new ManagedCommands<Context, ConversationContext, CommandAccess>({
adapter,
plugins: [
(ctx, next) => {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CommandsCollection } from "@/lib/managed-commands"
import { fmt } from "@/utils/format"
import { ephemeral } from "@/utils/messages"

export const invite = new CommandsCollection<string, CommandAccess>().createCommand({
export const invite = new CommandsCollection<CommandAccess>().createCommand({
trigger: "invite",
description: "Display the bot's invite link of the group",
scope: "group",
Expand Down
6 changes: 3 additions & 3 deletions src/commands/management/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CommandsCollection } from "@/lib/managed-commands"
import { fmt, fmtDate } from "@/utils/format"
import { getTelegramId } from "@/utils/telegram-id"

export const audit = new CommandsCollection<string, CommandAccess>("Auditing").createCommand({
export const audit = new CommandsCollection<CommandAccess>("Auditing").createCommand({
trigger: "audit",
scope: "private",
description: "Get the audit log of a user",
Expand All @@ -31,8 +31,8 @@ export const audit = new CommandsCollection<string, CommandAccess>("Auditing").c
({ b, n, i, u, link, code }) => [
b`🧾 Audit Log: ${args.username}\n`,
...list.flatMap((el) => {
// Automatic actions have no human actor (RFC v3 §9.2); older rows only have adminId.
const actorId = el.actorTgId ?? el.adminId
// Automatic actions have no human actor (RFC v3 §9.2).
const actorId = el.actorTgId
return [
`------------------------------------`,
n`${u`${b`${el.type.toUpperCase()}`}`} ${i`at ${fmtDate(el.createdAt)}`}`,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/management/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { GroupManagement } from "@/lib/group-management"
import { CommandsCollection } from "@/lib/managed-commands"
import { fmt } from "@/utils/format"

export const groups = new CommandsCollection<string, CommandAccess>("Groups")
export const groups = new CommandsCollection<CommandAccess>("Groups")
.createCommand({
trigger: "updategroup",
scope: "private",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { groups } from "./groups"
import { role } from "./role"
import { userid } from "./userid"

export const management = new CommandsCollection<string, CommandAccess>("Management").withCollection(
export const management = new CommandsCollection<CommandAccess>("Management").withCollection(
audit,
groups,
role,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/management/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { fmt } from "@/utils/format"
import { getTelegramId } from "@/utils/telegram-id"
import { numberOrString } from "@/utils/types"

export const role = new CommandsCollection<string, CommandAccess>("Roles").createCommand({
export const role = new CommandsCollection<CommandAccess>("Roles").createCommand({
trigger: "getroles",
scope: "private",
description: "Get roles of an user",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/management/userid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { logger } from "@/logger"
import { fmt } from "@/utils/format"
import { getTelegramId } from "@/utils/telegram-id"

export const userid = new CommandsCollection<string, CommandAccess>("User IDs").createCommand({
export const userid = new CommandsCollection<CommandAccess>("User IDs").createCommand({
trigger: "userid",
scope: "private",
description: "Gets the ID of a username",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/moderation/ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getTelegramId } from "@/utils/telegram-id"
import { numberOrString } from "@/utils/types"
import { getOverloadUser, getUser } from "@/utils/users"

export const ban = new CommandsCollection<string, CommandAccess>("Banning")
export const ban = new CommandsCollection<CommandAccess>("Banning")
.createCommand({
trigger: "ban",
args: [
Expand Down
2 changes: 1 addition & 1 deletion src/commands/moderation/banall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { fmt } from "@/utils/format"
import { getTelegramId } from "@/utils/telegram-id"
import { numberOrString } from "@/utils/types"

export const banAll = new CommandsCollection<string, CommandAccess>("Ban All")
export const banAll = new CommandsCollection<CommandAccess>("Ban All")
.createCommand({
trigger: "ban_all",
description: "PERMA BAN a user from all the Network's groups",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/moderation/del.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Moderation } from "@/modules/moderation"
import { fmt } from "@/utils/format"
import { ephemeral, getText } from "@/utils/messages"

export const del = new CommandsCollection<string, CommandAccess>("Deletion").createCommand({
export const del = new CommandsCollection<CommandAccess>("Deletion").createCommand({
trigger: "del",
scope: "group",
permissions: {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/moderation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { del } from "./del"
import { kick } from "./kick"
import { mute } from "./mute"

export const moderation = new CommandsCollection<string, CommandAccess>("Moderation").withCollection(
export const moderation = new CommandsCollection<CommandAccess>("Moderation").withCollection(
ban,
banAll,
del,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/moderation/kick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { logger } from "@/logger"
import { Moderation, moderatorFor } from "@/modules/moderation"
import { ephemeral } from "@/utils/messages"

export const kick = new CommandsCollection<string, CommandAccess>("Kicking").createCommand({
export const kick = new CommandsCollection<CommandAccess>("Kicking").createCommand({
trigger: "kick",
args: [{ key: "reason", optional: true, description: "Optional reason to kick the user" }],
description: "Kick a user from a group",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/moderation/mute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getTelegramId } from "@/utils/telegram-id"
import { numberOrString } from "@/utils/types"
import { getOverloadUser, getUser } from "@/utils/users"

export const mute = new CommandsCollection<string, CommandAccess>("Muting")
export const mute = new CommandsCollection<CommandAccess>("Muting")
.createCommand({
trigger: "tmute",
args: [
Expand Down
2 changes: 1 addition & 1 deletion src/commands/pin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CommandsCollection } from "@/lib/managed-commands"
import { fmt } from "@/utils/format"
import { ephemeral } from "@/utils/messages"

export const pin = new CommandsCollection<string, CommandAccess>()
export const pin = new CommandsCollection<CommandAccess>()
.createCommand({
trigger: "pin",
description: "Pin a message in a group",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const logReport = async (context: Filter<Context, "message"> | CommandSco
})
}

export const report = new CommandsCollection<string, CommandAccess>().createCommand({
export const report = new CommandsCollection<CommandAccess>().createCommand({
trigger: ["report", "admin"],
description: "Report a message to admins",
scope: "group",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const LIMIT = 9
type Group = Awaited<ReturnType<typeof serviceBackend.tg.groups.search.query>>["groups"][number]
type LinkedGroup = Group & { link: string }

export const search = new CommandsCollection<string, CommandAccess>().createCommand({
export const search = new CommandsCollection<CommandAccess>().createCommand({
trigger: "search",
scope: "both",
description: "Search groups by title",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/test/args.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CommandAccess } from "@/commands/access"
import { CommandsCollection } from "@/lib/managed-commands"

export const testargs = new CommandsCollection<string, CommandAccess>().createCommand({
export const testargs = new CommandsCollection<CommandAccess>().createCommand({
trigger: "test_args",
scope: "private",
description: "Test args",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/test/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { CommandAccess } from "@/commands/access"
import { CommandsCollection } from "@/lib/managed-commands"
import { fmt } from "@/utils/format"

export const testconvo = new CommandsCollection<string, CommandAccess>().createCommand({
export const testconvo = new CommandsCollection<CommandAccess>().createCommand({
trigger: "test_convo",
scope: "private",
description: "Test conversation",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/test/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { CommandAccess } from "@/commands/access"
import { CommandsCollection } from "@/lib/managed-commands"
import { fmt } from "@/utils/format"

export const testformat = new CommandsCollection<string, CommandAccess>().createCommand({
export const testformat = new CommandsCollection<CommandAccess>().createCommand({
trigger: "test_format",
scope: "private",
description: "Test the formatting",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { testconvo } from "./conversation"
import { testformat } from "./format"
import { testmenu } from "./menu"

export const test = new CommandsCollection<string, CommandAccess>("Test").withCollection(
export const test = new CommandsCollection<CommandAccess>("Test").withCollection(
testargs,
testformat,
testmenu,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/test/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const generateMenu = MenuGenerator.getInstance().create<{
],
])

export const testmenu = new CommandsCollection<string, CommandAccess>().createCommand({
export const testmenu = new CommandsCollection<CommandAccess>().createCommand({
trigger: "testmenu",
scope: "private",
description: "Quick conversation",
Expand Down
12 changes: 6 additions & 6 deletions src/lib/managed-commands/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type {
DefaultAccessControl,
} from "./command"

export class CommandsCollection<TRole extends string, TAccess extends AccessControl = DefaultAccessControl> {
export class CommandsCollection<TAccess extends AccessControl = DefaultAccessControl> {
private flushed = false
private commands: AnyCommand<TRole, Context, TAccess>[] = []
private commands: AnyCommand<Context, TAccess>[] = []

constructor(public name?: string) {}

Expand All @@ -21,24 +21,24 @@ export class CommandsCollection<TRole extends string, TAccess extends AccessCont
* @returns `this` instance for chaining
*/
createCommand<const A extends CommandArgs, const R extends CommandReplyTo, const S extends CommandScope>(
cmd: Command<A, R, S, TRole, Context, TAccess>
): CommandsCollection<TRole, TAccess> {
cmd: Command<A, R, S, Context, TAccess>
): CommandsCollection<TAccess> {
if (this.flushed) {
throw new Error("Cannot add commands after the collection has been flushed")
}
this.commands.push(cmd)
return this
}

withCollection(...collections: CommandsCollection<TRole, TAccess>[]): CommandsCollection<TRole, TAccess> {
withCollection(...collections: CommandsCollection<TAccess>[]): CommandsCollection<TAccess> {
if (this.flushed) {
throw new Error("Cannot add commands after the collection has been flushed")
}
this.commands.push(...collections.flatMap((c) => c.flush()))
return this
}

flush(): AnyCommand<TRole, Context, TAccess>[] {
flush(): AnyCommand<Context, TAccess>[] {
if (this.flushed) {
throw new Error("The collection has already been flushed")
}
Expand Down
Loading
Loading