Skip to content

Commit

Permalink
Merge pull request #38 from mineral-dart/develop
Browse files Browse the repository at this point in the history
feat: Get features from BETA
  • Loading branch information
LeadcodeDev authored Jul 16, 2022
2 parents fa43b6e + a3dd402 commit 86de712
Show file tree
Hide file tree
Showing 104 changed files with 1,933 additions and 438 deletions.
1 change: 1 addition & 0 deletions .pubignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assets/
48 changes: 14 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,19 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
# Mineral
![banner](https://raw.githubusercontent.com/mineral-dart/core/develop/assets/images/banner.png)

For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
Mineral is a robust, powerful and scalable framework designed to let you develop discord bots with the Dart language.

For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->
The Mineral framework currently allows you to use the latest Discord features:
- Slashcommands/Subcommands/Subcommand group
- Modals
- Scheduled events
- Auto-moderation
- Select menus
- Buttons
- Ephemeral messages

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
And much more...

## Features
Join our ranks and add your contribution to the best discord framework for Dart 💪

TODO: List what your package can do. Maybe include images, gifs, or videos.

## Getting started

TODO: List prerequisites and provide or point to information on how to
start using the package.

## Usage

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.

```dart
const like = 'sample';
```

## Additional information

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
https://github.com/mineral-dart
Binary file added assets/images/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion bin/mineral.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:args/args.dart';
import 'package:mineral/api.dart';
import 'package:mineral/core.dart';
import 'package:mineral/src/internal/entities/cli_manager.dart';
import 'package:mineral/src/internal/managers/cli_manager.dart';

Future<void> main (List<String> arguments) async {
Kernel kernel = Kernel();
kernel.loadConsole();

final ArgParser parser = ArgParser();

final makeCommandParser = ArgParser();
Expand Down
2 changes: 2 additions & 0 deletions dartdoc_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dartdoc:
favicon: assets/images/icon.png
10 changes: 4 additions & 6 deletions lib/api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/// The api is the Map of all the classes, enumerations of the framework
///
/// {@category Api}
library api;

export 'src/api/client/mineral_client.dart' show MineralClient, ClientActivity, ClientStatus, Intent;
Expand All @@ -11,8 +9,7 @@ export 'src/api/user.dart' show User;
export 'src/api/status.dart' show Status, StatusType;
export 'src/api/activity.dart' show Activity;
export 'src/api/guilds/guild_member.dart' show GuildMember;
export 'src/api/guilds/member_role_manager.dart' show MemberRoleManager;
export 'src/api/voice.dart' show Voice;
export 'src/api/managers/member_role_manager.dart' show MemberRoleManager;

export 'src/api/guilds/guild.dart' show Guild;
export 'src/api/moderation_rule.dart' show ModerationEventType, ModerationTriggerType, ModerationPresetType, ModerationActionType, ModerationTriggerMetadata, ModerationActionMetadata, ModerationAction, ModerationRule;
Expand All @@ -27,8 +24,8 @@ export 'src/api/channels/text_based_channel.dart' show TextBasedChannel;
export 'src/api/channels/text_channel.dart' show TextChannel;
export 'src/api/channels/category_channel.dart' show CategoryChannel;

export 'src/api/message.dart' show Message;
export 'src/api/message_embed.dart' show MessageEmbed, Footer, Image, Author, Field;
export 'src/api/messages/message.dart' show Message;
export 'src/api/messages/message_embed.dart' show MessageEmbed, Footer, Image, Thumbnail, Author, Field;
export 'src/api/color.dart' show Color;

export 'src/api/emoji.dart' show Emoji;
Expand All @@ -48,5 +45,6 @@ export 'src/api/interactions/select_menu_interaction.dart' show SelectMenuIntera

export 'src/api/utils.dart';
export 'src/internal/extensions/collection.dart';
export 'src/internal/extensions/string.dart';

typedef Snowflake = String;
41 changes: 30 additions & 11 deletions lib/console.dart
Original file line number Diff line number Diff line change
@@ -1,56 +1,75 @@
/// Console to print formatted and beautifully messages
library console;

import 'package:mineral/core.dart';
import 'package:mineral/src/internal/managers/reporter_manager.dart';

class Console {
static void log ({ required String message, String level = "info"}) {
if(level == "debug") {
static void log ({ required String message, String level = 'info'}) {
if (level == 'debug') {
final Environment environment = ioc.singleton(ioc.services.environment);
final String? logLevel = environment.get('LOG_LEVEL');

if (logLevel != "debug") return;
if (logLevel != 'debug') return;
}

print(message);
}

static debug ({ String prefix = 'debug', required String message }) {
ReporterManager? reporter = ioc.singleton(ioc.services.reporter);

if (reporter != null && reporter.reportLevel == 'debug') {
_report('[ $prefix ] $message');
}

String p = ColorList.white(prefix);
log(message: "[ $p ] $message", level: "debug");
log(message: '[ $p ] $message', level: 'debug');
}

static info ({ String prefix = 'info', required String message }) {
String p = ColorList.blue(prefix);
log(message: "[ $p ] $message", level: "info");
log(message: '[ $p ] $message', level: 'info');
_report('[ $prefix ] $message');
}

static success ({ String prefix = 'success', required String message }) {
String p = ColorList.green(prefix);
log(message: "[ $p ] $message", level: "info");
log(message: '[ $p ] $message', level: 'info');
_report('[ $prefix ] $message');
}

static error ({ String prefix = 'error', required String message }) {
log(message: getErrorMessage(prefix: ColorList.red(prefix), message: message), level: "error");
log(message: getErrorMessage(prefix: ColorList.red(prefix), message: message), level: 'error');
_report('[ $prefix ] $message');
}

static warn ({ String prefix = 'warn', required String message }) {
log(message: getWarnMessage(prefix: ColorList.yellow(prefix), message: message), level: "warn");
log(message: getWarnMessage(prefix: ColorList.yellow(prefix), message: message), level: 'warn');
_report('[ $prefix ] $message');
}

static String getWarnMessage ({ String? prefix = 'warn', required String message }) {
String p = ColorList.yellow(prefix!);
return "[ $p ] $message";
return '[ $p ] $message';
}

static String getErrorMessage ({ String? prefix = 'error', required String message }) {
String p = ColorList.red(prefix!);
return "[ $p ] $message";
return '[ $p ] $message';
}

static _report (String message) {
ReporterManager? reporter = ioc.singleton(ioc.services.reporter);
if (reporter != null) {
reporter.write(message);
}
}
}

class ColorList {
static String black (String text) => '\x1B[30m$text\x1B[0m';
static String red (String text) => '\x1B[31m$text\x1B[0m';
static String red (String text) => '\x1B[186m$text\x1B[0m';
static String green (String text) => '\x1B[32m$text\x1B[0m';
static String yellow (String text) => '\x1B[33m$text\x1B[0m';
static String blue (String text) => '\x1B[34m$text\x1B[0m';
Expand Down
9 changes: 5 additions & 4 deletions lib/core.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// 🧡 The neuralgic heart of the application, this module gathers all the functionalities of the framework.
library core;

export 'src/internal/environment.dart' show Environment;
Expand All @@ -7,7 +8,7 @@ export 'src/internal/ioc.dart' show ioc, Service;

export 'src/constants.dart';
export 'src/internal/http.dart';
export 'src/internal/entities/event_manager.dart' show Event, Events, MineralEvent;
export 'src/internal/entities/command_manager.dart' show Command, MineralCommand, Option, OptionType, OptionChoice, Subcommand, CommandGroup;
export 'src/internal/entities/store_manager.dart' show Store, MineralStore;
export 'src/internal/entities/module_manager.dart' show Module, MineralModule;
export 'src/internal/managers/event_manager.dart' show Event, Events, MineralEvent;
export 'src/internal/managers/command_manager.dart' show Command, MineralCommand, Option, OptionType, OptionChoice, Subcommand, CommandGroup;
export 'src/internal/managers/store_manager.dart' show Store, MineralStore;
export 'src/internal/managers/module_manager.dart' show Module, MineralModule;
1 change: 1 addition & 0 deletions lib/exception.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// Core exceptions
library exception;

export 'src/exceptions/token_exception.dart';
Expand Down
14 changes: 1 addition & 13 deletions lib/helper.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// Helper class to simplify actions
library helper;

import 'dart:convert';
Expand Down Expand Up @@ -37,17 +38,4 @@ class Helper {

return _permissions;
}

static toPascalCase (String value) {
List<String> words = value.split('_');
return words.map((word) => "${word[0].toUpperCase()}${word.substring(1)}").join('');
}

static toCapitalCase (String value) {
return '${value[0].toUpperCase()}${value.substring(1)}';
}

static String toSnakeCase (String value) {
return value.split(RegExp(r"(?=[A-Z])")).join('_').toLowerCase();
}
}
5 changes: 2 additions & 3 deletions lib/internal.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// The internal library is the collection of all classes needed by the framework to work.
///
/// {@category Internal}
/// @nodoc
library internal;

export 'src/internal/websockets/websockets.dart';
export 'src/internal/websockets/websockets.dart';
1 change: 0 additions & 1 deletion lib/src/api/channels/category_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:convert';
import 'package:http/http.dart';
import 'package:mineral/api.dart';
import 'package:mineral/core.dart';
import 'package:mineral/src/api/channels/channel.dart';
import 'package:mineral/src/api/managers/webhook_manager.dart';

class CategoryChannel extends Channel {
Expand Down
17 changes: 13 additions & 4 deletions lib/src/api/channels/channel.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:http/http.dart';
import 'package:mineral/api.dart';
import 'package:mineral/core.dart';
import 'package:mineral/src/api/channels/partial_channel.dart';
import 'package:mineral/src/api/managers/webhook_manager.dart';

enum ChannelType {
Expand Down Expand Up @@ -36,8 +37,7 @@ Map<ChannelType, Channel Function(dynamic payload)> channels = {
// 'GUILD_FORUM': () => ,
};

class Channel {
Snowflake id;
class Channel extends PartialChannel {
ChannelType type;
Snowflake? guildId;
late Guild? guild;
Expand All @@ -50,7 +50,7 @@ class Channel {
WebhookManager webhooks;

Channel({
required this.id,
required id,
required this.type,
required this.guildId,
required this.position,
Expand All @@ -59,7 +59,7 @@ class Channel {
required this.parentId,
required this.flags,
required this.webhooks,
});
}): super(id: id);

Future<T> setLabel<T extends Channel> (String label) async {
Http http = ioc.singleton(ioc.services.http);
Expand Down Expand Up @@ -95,6 +95,15 @@ class Channel {
return this as T;
}

Future<bool> delete () async {
Http http = ioc.singleton(ioc.services.http);
Response response = await http.destroy(url: "/channels/$id");

guild?.channels.cache.remove(id);

return response.statusCode == 200;
}

@override
String toString () => "<#$id>";
}
38 changes: 38 additions & 0 deletions lib/src/api/channels/dm_channel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:mineral/api.dart';
import 'package:mineral/core.dart';
import 'package:mineral/src/api/channels/partial_channel.dart';
import 'package:mineral/src/api/managers/message_manager.dart';

class DmChannel extends PartialChannel {
Snowflake? lastMessageId;
MessageManager messages;
Map<Snowflake, User> recipients;

DmChannel({
required id,
required this.lastMessageId,
required this.messages,
required this.recipients,
}): super(id: id);

factory DmChannel.from({ required dynamic payload }) {
MineralClient client = ioc.singleton(ioc.services.client);

Map<Snowflake, User> users = {};
if (payload['recipients'] != null) {
for (dynamic element in payload['recipients']) {
User? user = client.users.cache.get(element['id']);
user ??= User.from(element);

users.putIfAbsent(user.id, () => user!);
}
}

return DmChannel(
id: payload['id'],
lastMessageId: payload['last_message_id'],
messages: MessageManager(payload['id'], null),
recipients: users
);
}
}
7 changes: 7 additions & 0 deletions lib/src/api/channels/partial_channel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:mineral/api.dart';

class PartialChannel {
Snowflake id;

PartialChannel({ required this.id });
}
4 changes: 2 additions & 2 deletions lib/src/api/channels/public_thread.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class PublicThread extends Channel {

String? name;
Snowflake? lastMessageId;
DateTime? lastPinTimstamp;
DateTime? lastPinTimestamp;

PublicThread({
required Snowflake id,
Expand Down Expand Up @@ -48,4 +48,4 @@ class PublicThread extends Channel {
webhooks: payload['webhooks'],
);
}
}
}
Loading

0 comments on commit 86de712

Please sign in to comment.