Skip to content

Commit

Permalink
bump version, improve color command, new color role command
Browse files Browse the repository at this point in the history
  • Loading branch information
IRONM00N committed Feb 2, 2024
1 parent 93d00db commit 0226cc4
Show file tree
Hide file tree
Showing 19 changed files with 1,254 additions and 992 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"**/CVS": true,
"**/.DS_Store": true,
"dist": false,
".pnp.js": false,
"**/node_modules": true
".pnp.js": false
// "**/node_modules": true
},
"search.exclude": {
"**/.yarn": true,
Expand Down
672 changes: 336 additions & 336 deletions .yarn/releases/yarn-4.0.2.cjs → .yarn/releases/yarn-4.1.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ pnpEnableEsmLoader: true

pnpMode: loose

yarnPath: .yarn/releases/yarn-4.0.2.cjs
yarnPath: .yarn/releases/yarn-4.1.0.cjs
86 changes: 43 additions & 43 deletions lib/automod/MessageAutomod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Time, colors } from '#lib/utils/Constants.js';
import { format, formatError } from '#lib/utils/Utils.js';
import { stripIndent } from '#tags';
//~ import chalk from 'chalk';
//// import chalk from 'chalk';
import { EmbedBuilder, PermissionFlagsBits, type GuildTextBasedChannel, type Message } from 'discord.js';
import assert from 'node:assert/strict';
import { Automod, Severity, type BadWordDetails } from './AutomodShared.js';
Expand Down Expand Up @@ -141,52 +141,52 @@ export class MessageAutomod extends Automod {
}
}

//~ protected async checkPerspectiveApi() {
//~ return;
//~ if (!this.client.config.isDevelopment) return;
//// protected async checkPerspectiveApi() {
//// return;
//// if (!this.client.config.isDevelopment) return;

//~ if (!this.message.content) return;
//~ this.client.perspective.comments.analyze(
//~ {
//~ key: this.client.config.credentials.perspectiveApiKey,
//~ resource: {
//~ comment: {
//~ text: this.message.content
//~ },
//~ requestedAttributes: {
//~ TOXICITY: {},
//~ SEVERE_TOXICITY: {},
//~ IDENTITY_ATTACK: {},
//~ INSULT: {},
//~ PROFANITY: {},
//~ THREAT: {},
//~ SEXUALLY_EXPLICIT: {},
//~ FLIRTATION: {}
//~ }
//~ }
//~ },
//~ (err: any, response: any) => {
//~ if (err) return console.log(err?.message);
//// if (!this.message.content) return;
//// this.client.perspective.comments.analyze(
//// {
//// key: this.client.config.credentials.perspectiveApiKey,
//// resource: {
//// comment: {
//// text: this.message.content
//// },
//// requestedAttributes: {
//// TOXICITY: {},
//// SEVERE_TOXICITY: {},
//// IDENTITY_ATTACK: {},
//// INSULT: {},
//// PROFANITY: {},
//// THREAT: {},
//// SEXUALLY_EXPLICIT: {},
//// FLIRTATION: {}
//// }
//// }
//// },
//// (err: any, response: any) => {
//// if (err) return console.log(err?.message);

//~ const normalize = (val: number, min: number, max: number) => (val - min) / (max - min);
//// const normalize = (val: number, min: number, max: number) => (val - min) / (max - min);

//~ const color = (val: number) => {
//~ if (val >= 0.5) {
//~ const x = 194 - Math.round(normalize(val, 0.5, 1) * 194);
//~ return chalk.rgb(194, x, 0)(val);
//~ } else {
//~ const x = Math.round(normalize(val, 0, 0.5) * 194);
//~ return chalk.rgb(x, 194, 0)(val);
//~ }
//~ };
//// const color = (val: number) => {
//// if (val >= 0.5) {
//// const x = 194 - Math.round(normalize(val, 0.5, 1) * 194);
//// return chalk.rgb(194, x, 0)(val);
//// } else {
//// const x = Math.round(normalize(val, 0, 0.5) * 194);
//// return chalk.rgb(x, 194, 0)(val);
//// }
//// };

//~ console.log(chalk.cyan(this.message.content));
//~ Object.entries(response.data.attributeScores)
//~ .sort(([a], [b]) => a.localeCompare(b))
//~ .forEach(([key, value]: any[]) => console.log(chalk.white(key), color(value.summaryScore.value)));
//~ }
//~ );
//~ }
//// console.log(chalk.cyan(this.message.content));
//// Object.entries(response.data.attributeScores)
//// .sort(([a], [b]) => a.localeCompare(b))
//// .forEach(([key, value]: any[]) => console.log(chalk.white(key), color(value.summaryScore.value)));
//// }
//// );
//// }

/**
* Punishes the user based on the severity of the offense
Expand Down
8 changes: 4 additions & 4 deletions lib/common/HighlightManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ export class HighlightManager {
*/
public readonly guildHighlights = new Collection<guild, Collection<word, users>>();

//~ /**
//~ * Cached global highlights.
//~ */
//~ public readonly globalHighlights = new Collection<word, users>();
//// /**
//// * Cached global highlights.
//// */
//// public readonly globalHighlights = new Collection<word, users>();

/**
* A collection of cooldowns of when a user last sent a message in a particular guild.
Expand Down
12 changes: 6 additions & 6 deletions lib/extensions/discord-akairo/BotCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ export interface BaseBotCommandOptions
/**
* Permissions required by the client to run this command.
*/
clientPermissions: PermissionsString[];
clientPermissions: Readonly<PermissionsString[]>;

/**
* Permissions required by the user to run this command.
*/
userPermissions: PermissionsString[];
userPermissions: Readonly<PermissionsString[]>;

/**
* Whether the argument is only accessible to the owners.
Expand Down Expand Up @@ -383,8 +383,8 @@ export abstract class BotCommand extends Command {
public declare client: TanzaniteClient;
public declare handler: BotCommandHandler;
public declare description: string;
public declare userPermissions: PermissionsString[];
public declare clientPermissions: PermissionsString[];
public declare userPermissions: Readonly<PermissionsString[]>;
public declare clientPermissions: Readonly<PermissionsString[]>;

/**
* Show how to use the command:
Expand Down Expand Up @@ -633,12 +633,12 @@ export type OptSlashArgType<T extends keyof CommandInteractionOption> = CommandI
/**
* `util` is always defined for messages after `'all'` inhibitors
*/
export type CommandMessage = Message & {
export type CommandMessage<InGuild extends boolean = boolean> = Message<InGuild> & {
/**
* Extra properties applied to the Discord.js message object.
* Utilities for command responding.
* Available on all messages after 'all' inhibitors and built-in inhibitors (bot, client).
* Not all properties of the util are available, depending on the input.
* */
util: CommandUtil<Message>;
util: CommandUtil<Message<InGuild>>;
};
15 changes: 9 additions & 6 deletions lib/extensions/discord-akairo/TanzaniteClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
import { patch, type PatchedElements } from '@tanzanite/events-intercept';
import {
ActivityType,
ClientUser,
GatewayIntentBits,
MessagePayload,
Options,
Expand All @@ -62,7 +63,7 @@ import {
type Snowflake,
type UserResolvable
} from 'discord.js';
//~import { google } from 'googleapis';
////import { google } from 'googleapis';
import assert from 'node:assert';
import type { EventEmitter } from 'node:events';
import path from 'node:path';
Expand Down Expand Up @@ -113,8 +114,8 @@ declare module 'discord.js' {
readonly sentry: typeof Sentry;
/** Manages most aspects of the highlight command */
readonly highlightManager: HighlightManager;
/** The perspective api */
//~ perspective: any;
/////** The perspective api */
////perspective: any;
/** Client utilities. */
readonly utils: BotClientUtils;
/** A custom logging system for the bot. */
Expand Down Expand Up @@ -220,7 +221,7 @@ export class TanzaniteClient<Ready extends boolean = boolean> extends AkairoClie
/**
* The perspective api
*/
//~ public override perspective: any;
//// public override perspective: any;

/**
* Client utilities.
Expand Down Expand Up @@ -391,10 +392,12 @@ export class TanzaniteClient<Ready extends boolean = boolean> extends AkairoClie
* Extends discord.js structures before the client is instantiated.
*/
public static extendStructures(): void {
Structures.extend('User', () => ExtendedUser);
Object.setPrototypeOf(ClientUser, ExtendedUser);
Object.setPrototypeOf(ClientUser.prototype, ExtendedUser.prototype);
Structures.extend('GuildMember', () => ExtendedGuildMember);
Structures.extend('Guild', () => ExtendedGuild);
Structures.extend('Message', () => ExtendedMessage);
Structures.extend('User', () => ExtendedUser);
}

/**
Expand All @@ -408,7 +411,7 @@ export class TanzaniteClient<Ready extends boolean = boolean> extends AkairoClie

this.setMaxListeners(20);

//~ this.perspective = await google.discoverAPI<any>('https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1');
//// this.perspective = await google.discoverAPI<any>('https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1');

this.commandHandler.useInhibitorHandler(this.inhibitorHandler);
this.commandHandler.useListenerHandler(this.listenerHandler);
Expand Down
6 changes: 3 additions & 3 deletions lib/extensions/discord.js/ExtendedGuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class ExtendedGuild extends Guild implements Extension {
if (
!logChannel
.permissionsFor(this.members.me!.id)
?.has([PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages, PermissionFlagsBits.EmbedLinks])
?.has([PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages, PermissionFlagsBits.EmbedLinks] as const)
)
return false;

Expand Down Expand Up @@ -517,11 +517,11 @@ export class ExtendedGuild extends Guild implements Extension {
success.set(channel.id, false);
continue;
}
if (!channel.permissionsFor(this.members.me!.id)?.has([PermissionFlagsBits.ManageChannels])) {
if (!channel.permissionsFor(this.members.me!.id)?.has(PermissionFlagsBits.ManageChannels)) {
errors.set(channel.id, new Error('client no permission'));
success.set(channel.id, false);
continue;
} else if (!channel.permissionsFor(moderator)?.has([PermissionFlagsBits.ManageChannels])) {
} else if (!channel.permissionsFor(moderator)?.has(PermissionFlagsBits.ManageChannels)) {
errors.set(channel.id, new Error('moderator no permission'));
success.set(channel.id, false);
continue;
Expand Down
2 changes: 1 addition & 1 deletion lib/extensions/discord.js/ExtendedMessage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandUtil } from '@tanzanite/discord-akairo';
import { Message, type Client } from 'discord.js';
import type { RawMessageData } from 'discord.js/typings/rawDataTypes.js';
import type { RawMessageData } from 'node_modules/discord.js/typings/rawDataTypes.mjs';

export class ExtendedMessage<InGuild extends boolean = boolean> extends Message<InGuild> {
public declare util: CommandUtil<Message<InGuild>>;
Expand Down
2 changes: 1 addition & 1 deletion lib/extensions/discord.js/ExtendedUser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Client, User } from 'discord.js';
import type { RawUserData } from 'discord.js/typings/rawDataTypes.js';
import type { RawUserData } from 'node_modules/discord.js/typings/rawDataTypes.mjs';
import type { TanzaniteClient } from '../discord-akairo/TanzaniteClient.js';

interface Extension {
Expand Down
36 changes: 34 additions & 2 deletions lib/utils/Arg.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BaseBotArgumentType, BotArgumentType, BotArgumentTypeCaster, CommandMessage, SlashMessage } from '#lib';
import type { BaseBotArgumentType, BotArgumentType, BotArgumentTypeCaster, BotCommand, CommandMessage, SlashMessage } from '#lib';
import { Argument, type Command, type Flag, type ParsedValuePredicate } from '@tanzanite/discord-akairo';
import type { Message } from 'discord.js';

Expand All @@ -17,7 +17,39 @@ export async function cast(
message: CommandMessage | SlashMessage,
phrase: string
): Promise<any> {
return Argument.cast.call(this, type as any, message.client.commandHandler.resolver, message as Message, phrase);
return Argument.cast(type as any, message.client.commandHandler.resolver, message as Message, phrase);
}

export async function castUnion<T extends ATC>(
type: T[],
command: BotCommand,
message: CommandMessage | SlashMessage,
phrase: string
): Promise<ATCR<T>>;
export async function castUnion<T extends KBAT>(
type: T[],
command: BotCommand,
message: CommandMessage | SlashMessage,
phrase: string
): Promise<BAT[T]>;
export async function castUnion(
type: (AT | ATC)[],
command: BotCommand,
message: CommandMessage | SlashMessage,
phrase: string
): Promise<any>;
export async function castUnion(
type: (AT | ATC)[],
command: BotCommand,
message: CommandMessage | SlashMessage,
phrase: string
): Promise<any> {
return await Argument.cast(
Argument.union(...(type as any)).bind(new Argument(command)),
message.client.commandHandler.resolver,
message as Message,
phrase as string
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ export function deepWriteable<T>(obj: T): DeepWritable<T> {
return obj as DeepWritable<T>;
}

export function formatPerms(permissions: PermissionsString[]) {
export function formatPerms(permissions: Readonly<PermissionsString[]>) {
return permissions.map((p) => format.inlineCode(mappings.permissions[p]?.name ?? p)).join(', ');
}

Expand Down
4 changes: 2 additions & 2 deletions misc/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function tooltip(item: RawNeuItem) {
ctx = itemRender.getContext('2d');

ctx.globalAlpha = 1.0;
//~ ctx.globalAlpha = 0.94;
//// ctx.globalAlpha = 0.94;
ctx.fillStyle = background;

// top outside
Expand All @@ -112,7 +112,7 @@ function tooltip(item: RawNeuItem) {
// middle
ctx.fillRect(2 * scale, 2 * scale, width - 4 * scale, height - 4 * scale);

//~ ctx.globalAlpha = 0.78;
//// ctx.globalAlpha = 0.78;
ctx.globalAlpha = 1.0;

const borderColorStart = parseInt(new tinycolor(getPrimaryColor(item.displayname)).toHex(), 16);
Expand Down
Loading

0 comments on commit 0226cc4

Please sign in to comment.