This commit is contained in:
Alex 2021-05-21 14:23:07 -05:00
parent 97ca10f53e
commit 9293af28dc
1 changed files with 47 additions and 30 deletions

View File

@ -2,8 +2,8 @@ import 'dart:async';
import 'dart:math';
import 'package:nyxx/nyxx.dart';
import 'package:nyxx_interactions/interactions.dart';
import 'package:nyxx_commander/commander.dart';
import 'package:nyxx_interactions/interactions.dart';
import 'package:osselbot/config.dart';
// import 'package:path/path.dart';
@ -18,10 +18,10 @@ void main(List<String> arguments) {
Interactions(bot)
..registerSlashCommand(SlashCommandBuilder(
'test',
'test command',
'info',
'gives bot info',
[],
)..registerHandler(testSlashCommand))
)..registerHandler((handler) => infoSlashCommand(handler, bot)))
..syncOnReady();
Commander(bot, prefix: '?')
@ -39,33 +39,11 @@ void main(List<String> arguments) {
})
..registerCommand('info', (context, message) async {
await context.sendMessage(
embed: await infoCommand(bot, context, message));
embed: await infoCommand(bot, context.guild, context.shardId));
});
}
Future<EmbedBuilder> infoCommand(
Nyxx bot, CommandContext context, String message) async {
var member = await context.guild?.fetchMember(bot.self.id);
var color = getColor(member ??= context.guild?.selfMember);
var iconUrl = bot.self.avatarURL();
return EmbedBuilder()
..addField(
name: 'ping',
content: bot.shardManager.shards
.elementAt(context.shardId)
.gatewayLatency
.inMilliseconds
.toString() +
'ms',
inline: true)
..addAuthor((author) {
author.iconUrl = iconUrl;
author.name = bot.self.username;
})
..color = color; // ??= DiscordColor.blue
}
// Bot routines
DiscordColor getColor(Member? member) {
if (member == null) return DiscordColor.black;
@ -89,8 +67,47 @@ void randomStatus(Nyxx bot) {
game: Activity.of(statuses[rand.nextInt(statuses.length - 1)])));
}
Future<void> testSlashCommand(InteractionEvent event) async {
// Command embeds
// Info
Future<EmbedBuilder> infoCommand(Nyxx bot, Guild? guild, int? shardId) async {
var member = await guild!.fetchMember(bot.self.id);
var color = getColor(member);
var iconUrl = bot.self.avatarURL();
int ping;
if (shardId != null) {
ping = bot.shardManager.shards
.elementAt(shardId)
.gatewayLatency
.inMilliseconds;
} else {
ping = bot.shardManager.gatewayLatency.inMilliseconds;
}
var uptimeString = bot.uptime.toString();
return EmbedBuilder()
..addField(name: 'Ping', content: ping.toString() + 'ms', inline: true)
..addField(
name: 'Uptime',
content: uptimeString.substring(0, uptimeString.length - 7),
inline: true)
..addAuthor((author) {
author.iconUrl = iconUrl;
author.name = bot.self.username;
})
..color = color;
}
// Command helpers
// /info command
Future<void> infoSlashCommand(InteractionEvent event, Nyxx bot) async {
await event.acknowledge();
await event.respond(content: 'hello, world');
await event.respond(
embed: await infoCommand(
bot, await event.interaction.guild!.getOrDownload(), null));
}