mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-24 03:00:09 -04:00
Got all commands running again
This commit is contained in:
committed by
Alec LaLonde
parent
5f96edd4ae
commit
702b33c4c3
@@ -45,8 +45,6 @@ export const playerRankUpdated = async (payload: TriggerPayload<PlayerRow>) => {
|
||||
|
||||
const guild = await discordClient.guilds.fetch(
|
||||
Constants.METAFAM_DISCORD_GUILD_ID,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
if (guild == null) {
|
||||
return;
|
||||
|
||||
@@ -39,8 +39,6 @@ export const playerRoleChanged = async (
|
||||
|
||||
const guild = await discordClient.guilds.fetch(
|
||||
Constants.METAFAM_DISCORD_GUILD_ID,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
if (guild == null) {
|
||||
return;
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Alias, sourcecred as sc } from 'sourcecred';
|
||||
|
||||
import { CONFIG } from '../../config';
|
||||
import { loadSourceCredLedger, resetLedger } from '../../sourcecred';
|
||||
import { replyWithUnexpectedError } from '../../utils';
|
||||
|
||||
const supportedPlatforms = ['github', 'discourse'];
|
||||
const errorSupportedPlatforms = `Supported platforms: ${supportedPlatforms.join(
|
||||
@@ -103,9 +104,11 @@ export class AddAlias {
|
||||
const platformAlias = existingIdentity.identity.aliases.find(
|
||||
(existingAlias) => {
|
||||
const parts = addressModule.toParts(existingAlias.address);
|
||||
console.log(parts);
|
||||
return parts[1] === trimmedPlatform;
|
||||
},
|
||||
);
|
||||
console.log(platformAlias);
|
||||
if (platformAlias != null) {
|
||||
const parts = addressModule.toParts(platformAlias.address);
|
||||
const existingPlatformIdentifier = parts[parts.length - 1];
|
||||
@@ -155,10 +158,8 @@ export class AddAlias {
|
||||
`Successfully added ${trimmedPlatform} alias: ${sanitizedId}.`,
|
||||
);
|
||||
} catch (e) {
|
||||
await message.reply(
|
||||
'MetaGameBot regrets to inform you of an unexpected error 😥. Contact a friendly Builder for assistance.',
|
||||
);
|
||||
console.error(e);
|
||||
await replyWithUnexpectedError(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { Constants, fetch } from '@metafam/utils';
|
||||
import { Command, CommandMessage } from '@typeit/discord';
|
||||
import { MessageEmbed, Snowflake } from 'discord.js';
|
||||
import {
|
||||
Discord,
|
||||
SimpleCommand,
|
||||
SimpleCommandMessage,
|
||||
SimpleCommandOption,
|
||||
} from 'discordx';
|
||||
import {
|
||||
SCAccount,
|
||||
SCAccountsData,
|
||||
@@ -10,19 +15,25 @@ import {
|
||||
|
||||
import { getDiscordId, replyWithUnexpectedError } from '../../utils';
|
||||
|
||||
@Discord()
|
||||
export class GetXpCommand {
|
||||
@Command('!mg xp :discordUser')
|
||||
async getXp(message: CommandMessage) {
|
||||
@SimpleCommand('xp')
|
||||
async getXp(
|
||||
@SimpleCommandOption('discord_user', { type: 'STRING' })
|
||||
discordUserAlias: string,
|
||||
command: SimpleCommandMessage,
|
||||
) {
|
||||
let targetUserDiscordId = '';
|
||||
const { message } = command;
|
||||
try {
|
||||
if (message.args.discordUser) {
|
||||
targetUserDiscordId = getDiscordId(message.args.discordUser);
|
||||
if (discordUserAlias) {
|
||||
targetUserDiscordId = getDiscordId(discordUserAlias);
|
||||
} else if (message.member?.id) {
|
||||
targetUserDiscordId = message.member.id;
|
||||
}
|
||||
} catch (e) {
|
||||
await message.reply(
|
||||
`Could not recognize user ${message.args.discordUser}. Try \`!mg help\` if you need help.`,
|
||||
`Could not recognize user ${discordUserAlias}. Try \`!mg help\` if you need help.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -55,53 +66,56 @@ export class GetXpCommand {
|
||||
|
||||
const description =
|
||||
message.member?.id === targetUserDiscordId
|
||||
? `${discordUser}, here is your XP progression in MetaGame`
|
||||
? `Here is your XP progression in MetaGame`
|
||||
: `Here is the XP progression of ${discordUser} in MetaGame`;
|
||||
|
||||
await message.reply(
|
||||
new MessageEmbed()
|
||||
.setColor('#ff3864')
|
||||
.setDescription(description)
|
||||
.setTitle(`MetaGame XP`)
|
||||
.setURL('https://xp.metagame.wtf/#/explorer')
|
||||
.setTimestamp()
|
||||
.setThumbnail(
|
||||
'https://raw.githubusercontent.com/sourcecred/sourcecred/master/src/assets/logo/rasterized/logo_64.png',
|
||||
)
|
||||
.addFields(
|
||||
{
|
||||
name: 'Total',
|
||||
value: `${Math.round(userTotalCred).toLocaleString()} XP`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: 'Last week ',
|
||||
value: `${userWeeklyCred[numWeeks - 1].toPrecision(3)} XP`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: 'Week before',
|
||||
value: `${userWeeklyCred[numWeeks - 2].toPrecision(4)} XP`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: 'Weekly Change',
|
||||
value: `${Math.round(variation)}%`,
|
||||
inline: true,
|
||||
},
|
||||
)
|
||||
.setFooter(
|
||||
'Bot made by MetaFam',
|
||||
'https://wiki.metagame.wtf/img/mg-crystal.png',
|
||||
),
|
||||
);
|
||||
await message.reply({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setColor('#ff3864')
|
||||
.setDescription(description)
|
||||
.setTitle(`MetaGame XP`)
|
||||
.setURL('https://xp.metagame.wtf/#/explorer')
|
||||
.setTimestamp()
|
||||
.setThumbnail(
|
||||
'https://raw.githubusercontent.com/sourcecred/sourcecred/master/src/assets/logo/rasterized/logo_64.png',
|
||||
)
|
||||
.addFields(
|
||||
{
|
||||
name: 'Total',
|
||||
value: `${Math.round(userTotalCred)} XP`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: 'Last week ',
|
||||
value: `${userWeeklyCred[numWeeks - 1].toPrecision(3)} XP`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: 'Week before',
|
||||
value: `${userWeeklyCred[numWeeks - 2].toPrecision(4)} XP`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: 'Weekly Change',
|
||||
value: `${Math.round(variation)}%`,
|
||||
inline: true,
|
||||
},
|
||||
)
|
||||
.setFooter({
|
||||
text: 'Bot made by MetaFam',
|
||||
iconURL: 'https://wiki.metagame.wtf/img/mg-crystal.png',
|
||||
}),
|
||||
],
|
||||
});
|
||||
} else {
|
||||
await message.reply(
|
||||
`I couldn't find ${discordUser} in the ledger! Have you registered yet?`,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
await replyWithUnexpectedError(message, (e as Error).message);
|
||||
console.error(e);
|
||||
await replyWithUnexpectedError(message, e as Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Command, CommandMessage } from '@typeit/discord';
|
||||
import { Discord, SimpleCommand, SimpleCommandMessage } from 'discordx';
|
||||
|
||||
const helpContent = `
|
||||
Available MetaGameBot commands:
|
||||
@@ -12,9 +12,10 @@ Available MetaGameBot commands:
|
||||
- !mg help → This command.
|
||||
`;
|
||||
|
||||
@Discord()
|
||||
export class HelpCommand {
|
||||
@Command('!mg help')
|
||||
async getHelp(message: CommandMessage) {
|
||||
await message.reply(helpContent);
|
||||
@SimpleCommand('help')
|
||||
async getXp(command: SimpleCommandMessage) {
|
||||
await command.message.reply(helpContent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,28 @@
|
||||
import { Command, CommandMessage } from '@typeit/discord';
|
||||
import {
|
||||
Discord,
|
||||
SimpleCommand,
|
||||
SimpleCommandMessage,
|
||||
SimpleCommandOption,
|
||||
} from 'discordx';
|
||||
import { sourcecred as sc } from 'sourcecred';
|
||||
|
||||
import { loadSourceCredLedger } from '../../sourcecred';
|
||||
|
||||
const addressUtils = sc.plugins.ethereum.utils.address;
|
||||
|
||||
type SetEthAddressArgs = {
|
||||
ethAddress: string;
|
||||
force: string;
|
||||
};
|
||||
|
||||
@Discord()
|
||||
export abstract class SetEthAddress {
|
||||
@Command('!mg setAddress :ethAddress :force')
|
||||
async setAddress(message: CommandMessage<SetEthAddressArgs>) {
|
||||
@SimpleCommand('setAddress')
|
||||
async setAddress(
|
||||
@SimpleCommandOption('eth_address', { type: 'STRING' })
|
||||
ethAddressInput: string,
|
||||
@SimpleCommandOption('force', { type: 'STRING' })
|
||||
force: string | undefined,
|
||||
command: SimpleCommandMessage,
|
||||
) {
|
||||
const res = await loadSourceCredLedger();
|
||||
const { result: reloadResult, manager } = res;
|
||||
const { message } = command;
|
||||
|
||||
if (reloadResult.error) {
|
||||
await message.reply(`Error Loading Ledger: ${reloadResult.error}`);
|
||||
@@ -31,7 +39,7 @@ export abstract class SetEthAddress {
|
||||
|
||||
let ethAddress: string;
|
||||
try {
|
||||
ethAddress = addressUtils.parseAddress(message.args.ethAddress);
|
||||
ethAddress = addressUtils.parseAddress(ethAddressInput);
|
||||
} catch (e) {
|
||||
await message.reply(`Invalid ETH Address.`);
|
||||
return;
|
||||
@@ -60,7 +68,7 @@ export abstract class SetEthAddress {
|
||||
|
||||
const latestEthAlias = existingEthAliases[existingEthAliases.length - 1];
|
||||
|
||||
const shouldForceUpdate = message.args.force === 'force';
|
||||
const shouldForceUpdate = force === 'force';
|
||||
|
||||
if (latestEthAlias && !shouldForceUpdate) {
|
||||
await message.reply(
|
||||
@@ -94,6 +102,7 @@ To force update your address, type \`!mg setAddress ${ethAddress} force\`.
|
||||
'Successfully linked ETH Address and activated account',
|
||||
);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
await message.reply(`Unable to link address: ${(e as Error).message}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,36 +17,31 @@ async function createDiscordClient(): Promise<Client> {
|
||||
);
|
||||
|
||||
const client = new Client({
|
||||
intents: [Intents.FLAGS.GUILD_MEMBERS],
|
||||
intents: [
|
||||
Intents.FLAGS.GUILDS,
|
||||
Intents.FLAGS.GUILD_MESSAGES, // required for simple commands it seems
|
||||
Intents.FLAGS.GUILD_MEMBERS,
|
||||
],
|
||||
silent: false,
|
||||
simpleCommand: {
|
||||
prefix: '!mg',
|
||||
prefix: '!mg ',
|
||||
responses: {
|
||||
notFound: (command: Message<boolean>) => {
|
||||
command.reply(`${CONFIG.botName} doesn't recognize that command.`);
|
||||
},
|
||||
},
|
||||
},
|
||||
botGuilds:
|
||||
process.env.RUNTIME_ENV === 'docker' ? undefined : ['808834438196494387'],
|
||||
});
|
||||
|
||||
client.once('ready', async () => {
|
||||
// make sure all guilds are in cache
|
||||
await client.guilds.fetch();
|
||||
});
|
||||
|
||||
// init all application commands
|
||||
await client.initApplicationCommands({
|
||||
guild: { log: true },
|
||||
global: { log: true },
|
||||
});
|
||||
|
||||
// init permissions; enabled log to see changes
|
||||
await client.initApplicationPermissions(true);
|
||||
|
||||
// uncomment this line to clear all guild commands,
|
||||
// useful when moving to global commands from guild commands
|
||||
// await client.clearApplicationCommands(
|
||||
// ...client.guilds.cache.map((g) => g.id)
|
||||
// );
|
||||
client.on('messageCreate', (message) => {
|
||||
client.executeCommand(message);
|
||||
});
|
||||
|
||||
await client.login(CONFIG.discordBotToken);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { CommandMessage } from '@typeit/discord';
|
||||
import { Message, Snowflake } from 'discord.js';
|
||||
|
||||
export const getDiscordId = (targetParameter: string): Snowflake => {
|
||||
@@ -17,8 +16,8 @@ export const getDiscordId = (targetParameter: string): Snowflake => {
|
||||
};
|
||||
|
||||
export const replyWithUnexpectedError = (
|
||||
message: CommandMessage,
|
||||
error: string,
|
||||
message: Message,
|
||||
error: Error,
|
||||
): Promise<Message> => {
|
||||
let reply = `The octo is sad 😢, as there was an unexpected error: "${error}"`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user