Skip to content

Commit

Permalink
Merge pull request #8 from edgedb/only-moderators-can-run-cmds
Browse files Browse the repository at this point in the history
Improve error for thread not being inside a help channel
  • Loading branch information
diksipav authored Oct 8, 2024
2 parents 08f5d10 + 49d84b0 commit 655066e
Show file tree
Hide file tree
Showing 48 changed files with 72 additions and 50 deletions.
3 changes: 1 addition & 2 deletions app/lib/discord/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,14 @@ export class Bot extends REST {
}

errorEmbed(msg?: string): APIEmbed {
console.log("Error:", msg);
return {
title: "Error",
description: msg ?? "There was an error executing your request",
color: 0xff0000,
};
}

defer(ephemeral: boolean = true): APIInteractionResponse {
defer(ephemeral = true): APIInteractionResponse {
return {
type: InteractionResponseType.DeferredChannelMessageWithSource,
data: {
Expand Down
3 changes: 2 additions & 1 deletion app/lib/discord/commands/helpful.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export default class HelpfulCommand
data: {
embeds: [
bot.errorEmbed(
`${threadChannel.parent_id}, ${bot["help-channels"].size}, ${ids}}`
"Thread is not inside a valid help channel."
// `${threadChannel.parent_id}, ${bot["help-channels"].size}, ${ids}}`
),
],
flags: MessageFlags.Ephemeral,
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/__spec__.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "./reflection";
const spec: $.introspect.Types = new $.StrictMap();
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/cardinality.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import { Cardinality } from "edgedb/dist/reflection/index";
import type { TypeSet } from "./typesystem";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/cast.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import { ExpressionKind, Cardinality } from "edgedb/dist/reflection/index";
import type {
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/castMaps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as edgedb from "edgedb";
import type * as $ from "./reflection";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/casting.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import type { Cardinality } from "edgedb/dist/reflection/index";
import type {
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/collections.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import {
Cardinality,
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/detached.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import { ExpressionKind } from "edgedb/dist/reflection/index";
import type { Expression, TypeSet } from "./typesystem";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/external.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

export { literal } from "./literal";
export {} from "./path";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/for.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import { Cardinality, ExpressionKind } from "edgedb/dist/reflection/index";
import { cardutil } from "./cardinality";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/funcops.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import {
Cardinality,
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/globals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import { type Cardinality, ExpressionKind } from "edgedb/dist/reflection/index";
import type { Expression, BaseType } from "./typesystem";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/group.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import type {
Expression,
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/hydrate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import type { $ } from "edgedb";

Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/imports.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

export * as edgedb from "edgedb";
export { spec } from "./__spec__";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

export * from "./external";
export { createClient } from "edgedb";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/insert.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import {
Cardinality,
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/json.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import { ExpressionKind, TypeKind } from "edgedb/dist/reflection/index";
import type { ParamType } from "./typesystem";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/literal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import type {
Expression,
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/modules/_default_10.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "../reflection";
import * as _ from "../imports";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/modules/cal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "../reflection";
import * as _ from "../imports";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/modules/cfg.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "../reflection";
import * as _ from "../imports";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/modules/default.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "../reflection";
import * as _ from "../imports";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/modules/discord.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "../reflection";
import * as _ from "../imports";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/modules/ext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "../reflection";
import * as _ from "../imports";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/modules/ext/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "../../reflection";
import * as _ from "../../imports";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/modules/ext/pgcrypto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "../../reflection";
import * as _ from "../../imports";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/modules/fts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "../reflection";
import * as _ from "../imports";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/modules/math.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "../reflection";
import * as _ from "../imports";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/modules/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "../reflection";
import * as _ from "../imports";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/modules/std.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "../reflection";
import * as _ from "../imports";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/modules/std/enc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "../../reflection";
import * as _ from "../../imports";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/modules/sys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "../reflection";
import * as _ from "../imports";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/operators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "./reflection";
import * as _ from "./imports";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/params.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import type { Executor } from "edgedb";
import {
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/path.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import {
// cardutil,
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/query.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import type * as edgedb from "edgedb";
import { Cardinality, ExpressionKind } from "edgedb/dist/reflection/index";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/range.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import type { LocalDate, LocalDateTime, Duration } from "edgedb";
import { Range } from "edgedb";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/reflection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

export * from "edgedb/dist/reflection/index";
export * from "./typesystem";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/select.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import {
LocalDateTime,
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/set.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import type { ExpressionKind, Cardinality } from "edgedb/dist/reflection/index";
import { TypeKind } from "edgedb/dist/reflection/index";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/setImpl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import * as $ from "./reflection";
import * as castMaps from "./castMaps";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/syntax.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import type { TypeSet, setToTsType } from "./typesystem";

Expand Down
26 changes: 24 additions & 2 deletions dbschema/edgeql-js/toEdgeQL.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import {
Duration,
Expand All @@ -8,6 +8,7 @@ import {
RelativeDuration,
DateDuration,
Range,
InputDataError,
} from "edgedb";
import {
Cardinality,
Expand Down Expand Up @@ -1450,13 +1451,34 @@ const numericalTypes: Record<string, boolean> = {
"std::float64": true,
};

function makeLabel(stringified: string): string {
const MAX_ITERATIONS = 100;
const prefix = "jsonliteral";
let counter = 0;
let label = `${prefix}`;

while (stringified.includes(`$${label}$`) && counter < MAX_ITERATIONS) {
label = `${prefix}${counter}`;
counter++;
}

if (counter >= MAX_ITERATIONS) {
throw new InputDataError(
"Counter reached 100 without finding a unique label.",
);
}
return label;
}

function literalToEdgeQL(type: BaseType, val: any): string {
const typename = (type as any).__casttype__?.__name__ ?? type.__name__;
let skipCast = false;
let stringRep;
if (typename === "std::json") {
skipCast = true;
stringRep = `to_json($$${JSON.stringify(val)}$$)`;
const stringified = JSON.stringify(val);
const label = `$${makeLabel(stringified)}$`;
stringRep = `to_json(${label}${JSON.stringify(val)}${label})`;
} else if (typeof val === "string") {
if (numericalTypes[typename]) {
skipCast = typename === type.__name__;
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/typesystem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import type { Executor } from "edgedb/dist/ifaces";
import type { $expr_PathNode, $expr_TypeIntersection, $pathify } from "./path";
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/update.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import {
ExpressionKind,
Expand Down
2 changes: 1 addition & 1 deletion dbschema/edgeql-js/with.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GENERATED by @edgedb/generate v0.5.4
// GENERATED by @edgedb/generate v0.5.6

import { type Cardinality, ExpressionKind } from "edgedb/dist/reflection/index";
import type { BaseType, Expression, TypeSet } from "./typesystem";
Expand Down

0 comments on commit 655066e

Please sign in to comment.