mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
statistics bug
This commit is contained in:
@@ -38,7 +38,7 @@ export class ClientStatisticsService {
|
|||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(ClientStatisticsEntity)
|
.from(ClientStatisticsEntity)
|
||||||
.where('time < :time', { time: oneDayAgo })
|
.where('time < :time', { time: oneDayAgo.getTime() })
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export class ClientService {
|
|||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(ClientEntity)
|
.from(ClientEntity)
|
||||||
.where('deletedAt < :time', { time: oneDayAgo })
|
.where('deletedAt < :deletedAt', { deletedAt: oneDayAgo })
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,11 @@ export class CleanupService implements OnModuleInit {
|
|||||||
|
|
||||||
@Cron(CronExpression.EVERY_HOUR)
|
@Cron(CronExpression.EVERY_HOUR)
|
||||||
private async deleteOldStatistics() {
|
private async deleteOldStatistics() {
|
||||||
const deletedStatistics = await this.clientStatisticsService.deleteOldStatistics();
|
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
|
||||||
console.log(`Deleted ${deletedStatistics.affected} old statistics`);
|
const deletedStatistics = await this.clientStatisticsService.deleteOldStatistics();
|
||||||
const deletedClients = await this.clientService.deleteOldClients();
|
console.log(`Deleted ${deletedStatistics.affected} old statistics`);
|
||||||
console.log(`Deleted ${deletedClients.affected} old clients`);
|
const deletedClients = await this.clientService.deleteOldClients();
|
||||||
|
console.log(`Deleted ${deletedClients.affected} old clients`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,96 +34,105 @@ export class DiscordService implements OnModuleInit {
|
|||||||
|
|
||||||
|
|
||||||
constructor(private readonly configService: ConfigService) {
|
constructor(private readonly configService: ConfigService) {
|
||||||
this.token = this.configService.get('DISCORD_BOT_TOKEN');
|
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
|
||||||
this.clientId = this.configService.get('DISCORD_BOT_CLIENTID');
|
this.token = this.configService.get('DISCORD_BOT_TOKEN');
|
||||||
this.guildId = this.configService.get('DISCORD_BOT_GUILD_ID');
|
this.clientId = this.configService.get('DISCORD_BOT_CLIENTID');
|
||||||
this.channelId = this.configService.get('DISCORD_BOT_CHANNEL_ID')
|
this.guildId = this.configService.get('DISCORD_BOT_GUILD_ID');
|
||||||
|
this.channelId = this.configService.get('DISCORD_BOT_CHANNEL_ID')
|
||||||
|
|
||||||
if (this.token == null || this.token.length < 1 ||
|
if (this.token == null || this.token.length < 1 ||
|
||||||
this.clientId == null || this.clientId.length < 1 ||
|
this.clientId == null || this.clientId.length < 1 ||
|
||||||
this.guildId == null || this.guildId.length < 1 ||
|
this.guildId == null || this.guildId.length < 1 ||
|
||||||
this.channelId == null || this.channelId.length < 1
|
this.channelId == null || this.channelId.length < 1
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('discord init')
|
||||||
|
|
||||||
|
this.commandCollection = new Collection();
|
||||||
|
commands.forEach(command => {
|
||||||
|
this.commandCollection.set(command.data.name, command);
|
||||||
|
});
|
||||||
|
this.bot = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
|
||||||
|
this.bot.login(this.token);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('discord init')
|
|
||||||
|
|
||||||
this.commandCollection = new Collection();
|
|
||||||
commands.forEach(command => {
|
|
||||||
this.commandCollection.set(command.data.name, command);
|
|
||||||
});
|
|
||||||
this.bot = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
|
|
||||||
this.bot.login(this.token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async onModuleInit(): Promise<void> {
|
async onModuleInit(): Promise<void> {
|
||||||
|
|
||||||
if (this.bot == null) {
|
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
|
||||||
return;
|
if (this.bot == null) {
|
||||||
}
|
|
||||||
|
|
||||||
await this.registerCommands();
|
|
||||||
|
|
||||||
|
|
||||||
this.bot.on(Events.InteractionCreate, async interaction => {
|
|
||||||
if (!interaction.isChatInputCommand()) return;
|
|
||||||
|
|
||||||
const command = this.commandCollection.get(interaction.commandName);
|
|
||||||
|
|
||||||
if (!command) {
|
|
||||||
console.error(`No command matching ${interaction.commandName} was found.`);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
await this.registerCommands();
|
||||||
await command.execute(interaction);
|
|
||||||
} catch (error) {
|
this.bot.on(Events.InteractionCreate, async interaction => {
|
||||||
console.error(error);
|
if (!interaction.isChatInputCommand()) return;
|
||||||
if (interaction.replied || interaction.deferred) {
|
|
||||||
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
|
const command = this.commandCollection.get(interaction.commandName);
|
||||||
} else {
|
|
||||||
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
|
if (!command) {
|
||||||
|
console.error(`No command matching ${interaction.commandName} was found.`);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
try {
|
||||||
|
await command.execute(interaction);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
if (interaction.replied || interaction.deferred) {
|
||||||
|
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
|
||||||
|
} else {
|
||||||
|
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async registerCommands() {
|
private async registerCommands() {
|
||||||
const rest = new REST().setToken(this.token);
|
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
|
||||||
try {
|
const rest = new REST().setToken(this.token);
|
||||||
console.log(`Started refreshing ${commands.length} application (/) commands.`);
|
try {
|
||||||
|
console.log(`Started refreshing ${commands.length} application (/) commands.`);
|
||||||
|
|
||||||
// The put method is used to fully refresh all commands in the guild with the current set
|
// The put method is used to fully refresh all commands in the guild with the current set
|
||||||
const data = await rest.put(
|
const data = await rest.put(
|
||||||
Routes.applicationGuildCommands(this.clientId, this.guildId),
|
Routes.applicationGuildCommands(this.clientId, this.guildId),
|
||||||
{ body: commands.map(c => c.data.toJSON()) },
|
{ body: commands.map(c => c.data.toJSON()) },
|
||||||
) as any;
|
) as any;
|
||||||
|
|
||||||
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
|
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// And of course, make sure you catch and log any errors!
|
// And of course, make sure you catch and log any errors!
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async notifyRestarted() {
|
public async notifyRestarted() {
|
||||||
if (this.bot == null) {
|
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
|
||||||
return;
|
if (this.bot == null) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const guild = await this.bot.guilds.fetch(this.guildId);
|
const guild = await this.bot.guilds.fetch(this.guildId);
|
||||||
const channel = await guild.channels.fetch(this.channelId) as TextChannel;
|
const channel = await guild.channels.fetch(this.channelId) as TextChannel;
|
||||||
channel.send(`Server Restarted.`);
|
channel.send(`Server Restarted.`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async notifySubscribersBlockFound(height: number, block: Block, message: string) {
|
public async notifySubscribersBlockFound(height: number, block: Block, message: string) {
|
||||||
if (this.bot == null) {
|
if (process.env.NODE_APP_INSTANCE == null || process.env.NODE_APP_INSTANCE == '0') {
|
||||||
return;
|
if (this.bot == null) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const guild = await this.bot.guilds.fetch(this.guildId);
|
const guild = await this.bot.guilds.fetch(this.guildId);
|
||||||
const channel = await guild.channels.fetch(this.channelId) as TextChannel;
|
const channel = await guild.channels.fetch(this.channelId) as TextChannel;
|
||||||
channel.send(`Block Found! Result: ${message}, Height: ${height}`)
|
channel.send(`Block Found! Result: ${message}, Height: ${height}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user