Ok lets see if I did this right
This commit is contained in:
parent
c9a68dfed6
commit
97ca10f53e
|
@ -8,10 +8,12 @@ include: package:pedantic/analysis_options.yaml
|
||||||
# Uncomment to specify additional rules.
|
# Uncomment to specify additional rules.
|
||||||
linter:
|
linter:
|
||||||
rules:
|
rules:
|
||||||
|
|
||||||
- camel_case_types
|
- camel_case_types
|
||||||
|
|
||||||
|
|
||||||
analyzer:
|
analyzer:
|
||||||
|
strong-mode:
|
||||||
|
implicit-casts: false
|
||||||
|
implicit-dynamic: false
|
||||||
# exclude:
|
# exclude:
|
||||||
# - path/to/excluded/files/**
|
# - path/to/excluded/files/**
|
||||||
|
|
|
@ -1,6 +1,96 @@
|
||||||
import 'package:osselbot/config.dart';
|
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:osselbot/config.dart';
|
||||||
|
// import 'package:path/path.dart';
|
||||||
|
|
||||||
void main(List<String> arguments) {
|
void main(List<String> arguments) {
|
||||||
|
final bot = Nyxx(Config['token'] as String, 32511);
|
||||||
|
bot.onReady.listen((event) {
|
||||||
|
randomStatus(bot);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Change the Activity every 5 minutes
|
||||||
|
Timer.periodic(Duration(minutes: 5), (timer) => randomStatus(bot));
|
||||||
|
|
||||||
|
Interactions(bot)
|
||||||
|
..registerSlashCommand(SlashCommandBuilder(
|
||||||
|
'test',
|
||||||
|
'test command',
|
||||||
|
[],
|
||||||
|
)..registerHandler(testSlashCommand))
|
||||||
|
..syncOnReady();
|
||||||
|
|
||||||
|
Commander(bot, prefix: '?')
|
||||||
|
..registerCommand(
|
||||||
|
'ping',
|
||||||
|
(context, message) => {
|
||||||
|
context.reply(
|
||||||
|
content: 'pong! ' +
|
||||||
|
bot.shardManager.shards
|
||||||
|
.elementAt(context.shardId)
|
||||||
|
.gatewayLatency
|
||||||
|
.inMilliseconds
|
||||||
|
.toString() +
|
||||||
|
'ms')
|
||||||
|
})
|
||||||
|
..registerCommand('info', (context, message) async {
|
||||||
|
await context.sendMessage(
|
||||||
|
embed: await infoCommand(bot, context, message));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
DiscordColor getColor(Member? member) {
|
||||||
|
if (member == null) return DiscordColor.black;
|
||||||
|
member.roles.forEach((element) async {
|
||||||
|
await element.getOrDownload();
|
||||||
|
});
|
||||||
|
|
||||||
|
var colorRole = member.roles.firstWhere((element) {
|
||||||
|
if (element.getFromCache()?.color == null) return false;
|
||||||
|
return element.getFromCache()?.color != DiscordColor.none;
|
||||||
|
});
|
||||||
|
return colorRole.getFromCache()!.color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void randomStatus(Nyxx bot) {
|
||||||
|
var rand = Random();
|
||||||
|
var statuses = Config['statuses'] as List<String>;
|
||||||
|
|
||||||
|
bot.setPresence(PresenceBuilder.of(
|
||||||
|
status: UserStatus.dnd,
|
||||||
|
game: Activity.of(statuses[rand.nextInt(statuses.length - 1)])));
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> testSlashCommand(InteractionEvent event) async {
|
||||||
|
await event.acknowledge();
|
||||||
|
|
||||||
|
await event.respond(content: 'hello, world');
|
||||||
}
|
}
|
||||||
|
|
18
pubspec.lock
18
pubspec.lock
|
@ -56,7 +56,21 @@ packages:
|
||||||
name: nyxx
|
name: nyxx
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.0-rc.4"
|
version: "2.0.0-rc.3"
|
||||||
|
nyxx_commander:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: nyxx_commander
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.0-rc.5"
|
||||||
|
nyxx_interactions:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: nyxx_interactions
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.0-rc.5"
|
||||||
path:
|
path:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -100,4 +114,4 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.0"
|
version: "1.3.0"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.12.0 <3.0.0"
|
dart: ">=2.12.0 <2.13.0"
|
||||||
|
|
11
pubspec.yaml
11
pubspec.yaml
|
@ -1,15 +1,18 @@
|
||||||
name: osselbot
|
name: osselbot
|
||||||
description: A stupid discord bot made for stupid people.
|
description: A stupid discord bot made for stupid people.
|
||||||
# version: 3.0.0
|
version: 3.0.0
|
||||||
# homepage: https://nicolor.tech/bot
|
homepage: https://nicolor.tech/bot
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.10.0 <3.0.0'
|
sdk: '>=2.12.0 <3.0.0'
|
||||||
|
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
nyxx: ^2.0.0-rc.4
|
nyxx: ^2.0.0-rc.3
|
||||||
|
nyxx_interactions: ^2.0.0-rc.5
|
||||||
|
nyxx_commander: ^2.0.0-rc.5
|
||||||
path: ^1.7.0
|
path: ^1.7.0
|
||||||
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
pedantic: ^1.9.0
|
pedantic: ^1.9.0
|
||||||
|
|
Loading…
Reference in New Issue