mirror of
https://github.com/Technicolor-creamsicle/Osselbot.git
synced 2025-10-18 11:44:06 -04:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
5b808e8873 | |||
9293af28dc | |||
|
97ca10f53e | ||
c9a68dfed6 | |||
0473958a16 | |||
|
04472c5192 | ||
|
6328d8508e | ||
|
2f440ec6ff |
29
.github/workflows/nodejs.yml
vendored
29
.github/workflows/nodejs.yml
vendored
@@ -1,29 +0,0 @@
|
||||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
||||
|
||||
name: Node.js CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: npm ci
|
||||
- run: npm run build --if-present
|
||||
- run: npm test
|
22
.gitignore
vendored
22
.gitignore
vendored
@@ -1,3 +1,19 @@
|
||||
.env
|
||||
# Added by cargo
|
||||
/target
|
||||
# Files and directories created by pub
|
||||
.dart_tool/
|
||||
.packages
|
||||
|
||||
# Conventional directory for build outputs
|
||||
build/
|
||||
|
||||
# Directory created by dartdoc
|
||||
doc/api/
|
||||
|
||||
# Vscode settings
|
||||
.vscode
|
||||
|
||||
# MacOS being funky
|
||||
.DS_Store
|
||||
|
||||
# Config file and executeables
|
||||
lib/config.dart
|
||||
bin/osselbot.exe
|
||||
|
3
CHANGELOG.md
Normal file
3
CHANGELOG.md
Normal file
@@ -0,0 +1,3 @@
|
||||
## 1.0.0
|
||||
|
||||
- Initial version, created by Stagehand
|
1274
Cargo.lock
generated
1274
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
13
Cargo.toml
13
Cargo.toml
@@ -1,13 +0,0 @@
|
||||
[package]
|
||||
name = "Osselbot"
|
||||
version = "0.1.0"
|
||||
authors = ["Michael Matthews <michaeldylanmatthews@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serenity = { version = "0.10.8", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
|
||||
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
||||
dotenv = "0.15.0"
|
||||
|
13
README.md
13
README.md
@@ -1,11 +1,4 @@
|
||||
# Osselbot
|
||||
A rusty bot that's kinda stupid, but it works surprisingly well
|
||||
|
||||
**THIS BOT REQUIRES HEAVY MODIFICATION TO WORK ON OTHER SERVERS!**
|
||||
**NPM PACKAGE IS NO LONGER MAINTAINED**
|
||||
|
||||
---
|
||||
# Contributing
|
||||
|
||||
If your a member of civilians all partying then talk to @Technicolor Creamsicle#0773 or @Gamma#0753
|
||||
A simple command-line application.
|
||||
|
||||
Created from templates made available by Stagehand under a BSD-style
|
||||
[license](https://github.com/dart-lang/stagehand/blob/master/LICENSE).
|
||||
|
19
analysis_options.yaml
Normal file
19
analysis_options.yaml
Normal file
@@ -0,0 +1,19 @@
|
||||
# Defines a default set of lint rules enforced for
|
||||
# projects at Google. For details and rationale,
|
||||
# see https://github.com/dart-lang/pedantic#enabled-lints.
|
||||
|
||||
include: package:pedantic/analysis_options.yaml
|
||||
|
||||
# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
|
||||
# Uncomment to specify additional rules.
|
||||
linter:
|
||||
rules:
|
||||
- camel_case_types
|
||||
|
||||
|
||||
analyzer:
|
||||
strong-mode:
|
||||
implicit-casts: false
|
||||
implicit-dynamic: false
|
||||
# exclude:
|
||||
# - path/to/excluded/files/**
|
111
bin/osselbot.dart
Normal file
111
bin/osselbot.dart
Normal file
@@ -0,0 +1,111 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:nyxx/nyxx.dart';
|
||||
import 'package:nyxx_commander/commander.dart';
|
||||
import 'package:nyxx_interactions/interactions.dart';
|
||||
import 'package:osselbot/config.dart';
|
||||
// import 'package:path/path.dart';
|
||||
|
||||
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(
|
||||
'info',
|
||||
'gives bot info',
|
||||
[],
|
||||
)..registerHandler((handler) => infoSlashCommand(handler, bot)))
|
||||
..syncOnReady();
|
||||
|
||||
Commander(bot, prefix: '?')
|
||||
..registerCommand(
|
||||
'ping',
|
||||
(context, message) => {
|
||||
context.reply(MessageBuilder.content('pong! ' +
|
||||
bot.shardManager.shards
|
||||
.elementAt(context.shardId)
|
||||
.gatewayLatency
|
||||
.inMilliseconds
|
||||
.toString() +
|
||||
'ms'))
|
||||
})
|
||||
..registerCommand('info', (context, message) async {
|
||||
await context.sendMessage(MessageBuilder.embed(
|
||||
await infoCommand(bot, context.guild, context.shardId)));
|
||||
});
|
||||
}
|
||||
|
||||
// Bot routines
|
||||
|
||||
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)])));
|
||||
}
|
||||
|
||||
// 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(MessageBuilder.embed(await infoCommand(
|
||||
bot, await event.interaction.guild!.getOrDownload(), null)));
|
||||
}
|
3
lib/config.dart
Normal file
3
lib/config.dart
Normal file
@@ -0,0 +1,3 @@
|
||||
Map<String, dynamic> Config = <String, dynamic>{
|
||||
'token': 'EXAMPLE TOKEN',
|
||||
};
|
117
pubspec.lock
Normal file
117
pubspec.lock
Normal file
@@ -0,0 +1,117 @@
|
||||
# Generated by pub
|
||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||
packages:
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: async
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.7.0"
|
||||
charcode:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: charcode
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: collection
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.15.0"
|
||||
http:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: http
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.13.3"
|
||||
http_parser:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: http_parser
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: logging
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
nyxx:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: nyxx
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0-rc.5"
|
||||
nyxx_commander:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: nyxx_commander
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0-rc.8"
|
||||
nyxx_interactions:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: nyxx_interactions
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0-rc.6"
|
||||
path:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: path
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.0"
|
||||
pedantic:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: pedantic
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.11.0"
|
||||
source_span:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: source_span
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.1"
|
||||
string_scanner:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: string_scanner
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: term_glyph
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: typed_data
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
sdks:
|
||||
dart: ">=2.12.0 <3.0.0"
|
18
pubspec.yaml
Normal file
18
pubspec.yaml
Normal file
@@ -0,0 +1,18 @@
|
||||
name: osselbot
|
||||
description: A stupid discord bot made for stupid people.
|
||||
version: 3.0.0
|
||||
homepage: https://nicolor.tech/bot
|
||||
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
|
||||
|
||||
dependencies:
|
||||
nyxx: ^2.0.0-rc.5
|
||||
nyxx_interactions: ^2.0.0-rc.5
|
||||
nyxx_commander: ^2.0.0-rc.5
|
||||
path: ^1.7.0
|
||||
|
||||
|
||||
dev_dependencies:
|
||||
pedantic: ^1.9.0
|
66
src/main.rs
66
src/main.rs
@@ -1,66 +0,0 @@
|
||||
#![allow(non_snake_case)] //Osselbot doesn't follow snake case so we need this
|
||||
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
|
||||
use serenity::{
|
||||
async_trait,
|
||||
model::{channel::Message, gateway::Ready},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
struct Handler;
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {
|
||||
// Set a handler for the `message` event - so that whenever a new message
|
||||
// is received - the closure (or function) passed will be called.
|
||||
//
|
||||
// Event handlers are dispatched through a threadpool, and so multiple
|
||||
// events can be dispatched simultaneously.
|
||||
async fn message(&self, ctx: Context, msg: Message) {
|
||||
if msg.content == "!ping" {
|
||||
// Sending a message can fail, due to a network error, an
|
||||
// authentication error, or lack of permissions to post in the
|
||||
// channel, so log to stdout when some error happens, with a
|
||||
// description of it.
|
||||
if let Err(why) = msg.channel_id.say(&ctx.http, "Pong!").await {
|
||||
println!("Error sending message: {:?}", why);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set a handler to be called on the `ready` event. This is called when a
|
||||
// shard is booted, and a READY payload is sent by Discord. This payload
|
||||
// contains data like the current user's guild Ids, current user data,
|
||||
// private channels, and more.
|
||||
//
|
||||
// In this case, just print what the current user's username is.
|
||||
async fn ready(&self, _: Context, ready: Ready) {
|
||||
println!("{} is connected!", ready.user.name);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
dotenv().ok();
|
||||
// Configure the client with your Discord bot token in the environment.
|
||||
let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
|
||||
|
||||
// Create a new instance of the Client, logging in as a bot. This will
|
||||
// automatically prepend your bot token with "Bot ", which is a requirement
|
||||
// by Discord for bot users.
|
||||
let mut client =
|
||||
Client::builder(&token)
|
||||
.event_handler(Handler)
|
||||
.await
|
||||
.expect("Err creating client");
|
||||
|
||||
// Finally, start a single shard, and start listening to events.
|
||||
//
|
||||
// Shards will automatically attempt to reconnect, and will perform
|
||||
// exponential backoff until it reconnects.
|
||||
if let Err(why) = client.start().await {
|
||||
println!("Client error: {:?}", why);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user