Skip to content

Commit

Permalink
Command client!
Browse files Browse the repository at this point in the history
  • Loading branch information
Hackzzila committed Sep 25, 2016
1 parent 5521571 commit 0696865
Show file tree
Hide file tree
Showing 46 changed files with 134 additions and 94 deletions.
16 changes: 16 additions & 0 deletions example/command-client.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:discord_dart/discord.dart' as discord;
import 'package:discord_dart/command.dart' as command;

main() {
var bot = new discord.Client("your token");
var commands = new command.Client(bot, "!");

bot.on('ready', (e) {
print("Ready!");
});

commands.on('ping', (e) {
var m = e.message;
m.channel.sendMessage("Pong!");
});
}
1 change: 1 addition & 0 deletions lib/command.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'src/command.dart';
39 changes: 39 additions & 0 deletions lib/discord.dart
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
export 'src/client.dart';

export 'src/events/ChannelCreateEvent.dart';
export 'src/events/ChannelDeleteEvent.dart';
export 'src/events/ChannelUpdateEvent.dart';
export 'src/events/GuildBanAddEvent.dart';
export 'src/events/GuildBanRemoveEvent.dart';
export 'src/events/GuildCreateEvent.dart';
export 'src/events/GuildDeleteEvent.dart';
export 'src/events/GuildMemberAddEvent.dart';
export 'src/events/GuildMemberRemoveEvent.dart';
export 'src/events/GuildMemberUpdateEvent.dart';
export 'src/events/GuildUpdateEvent.dart';
export 'src/events/MessageDeleteEvent.dart';
export 'src/events/MessageEvent.dart';
export 'src/events/MessageUpdateEvent.dart';
export 'src/events/ReadyEvent.dart';
export 'src/events/TypingEvent.dart';
export 'src/events/WebSocketErrorEvent.dart';

export 'src/objects/Attachment.dart';
export 'src/objects/ClientOAuth2Application.dart';
export 'src/objects/ClientOptions.dart';
export 'src/objects/ClientUser.dart';
export 'src/objects/Embed.dart';
export 'src/objects/EmbedProvider.dart';
export 'src/objects/EmbedThumbnail.dart';
export 'src/objects/Guild.dart';
export 'src/objects/GuildChannel.dart';
export 'src/objects/Invite.dart';
export 'src/objects/InviteChannel.dart';
export 'src/objects/InviteGuild.dart';
export 'src/objects/Member.dart';
export 'src/objects/MessageOptions.dart';
export 'src/objects/Message.dart';
export 'src/objects/OAuth2Application.dart';
export 'src/objects/OAuth2Guild.dart';
export 'src/objects/OAuth2Info.dart';
export 'src/objects/PrivateChannel.dart';
export 'src/objects/User.dart';
17 changes: 0 additions & 17 deletions lib/events.dart

This file was deleted.

20 changes: 0 additions & 20 deletions lib/objects.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/src/client.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:convert';
import 'dart:async';
import '../objects.dart';
import 'http.dart';
import 'ws.dart';
import '../discord.dart';
import 'package:events/events.dart' as events;
import 'package:http/http.dart' as http;

Expand Down
37 changes: 37 additions & 0 deletions lib/src/command.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import '../discord.dart' as discord;
import 'package:events/events.dart' as events;

/// Send when a new command is received.
class CommandEvent {
/// A list of arguments provided.
List<String> args;

/// The message;
discord.Message message;

/// Constructs a `CommandEvent`.
CommandEvent(Client client, String command, this.args, this.message) {
client.emit(command, this);
}
}

/// The base class for the command client.
class Client extends events.Events {
/// The main discord client.
discord.Client client;

/// The client's prefix.
String prefix;

/// Makes a new command client.
Client(this.client, this.prefix) {
this.client.on('message', (discord.MessageEvent e) {
if (e.message.content.startsWith(this.prefix)) {
final String command = e.message.content.split(" ")[0].replaceFirst(this.prefix, "");
final List<String> args = e.message.content.split(" ");
args.remove(this.prefix + command);
new CommandEvent(this, command, args, e.message);
}
});
}
}
2 changes: 1 addition & 1 deletion lib/src/events/ChannelCreateEvent.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';
import '../client.dart';

/// Sent when a channel is created, can be a `PMChannel`.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/events/ChannelDeleteEvent.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';
import '../client.dart';

/// Sent when a channel is deleted, can be a `PMChannel`.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/events/ChannelUpdateEvent.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';
import '../client.dart';

/// Sent when a channel is updated.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/events/GuildBanAddEvent.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';
import '../client.dart';

/// Sent when a member is banned.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/events/GuildBanRemoveEvent.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';
import '../client.dart';

/// Sent when a user is unbanned from a guild.
Expand Down
3 changes: 1 addition & 2 deletions lib/src/events/GuildCreateEvent.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '../../objects.dart';
import '../../events.dart';
import '../../discord.dart';
import '../client.dart';

/// Sent when the bot joins a guild.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/events/GuildDeleteEvent.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';
import '../client.dart';

/// Sent when you leave a guild or it becomes unavailable.
Expand Down
3 changes: 1 addition & 2 deletions lib/src/events/GuildMemberAddEvent.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '../../objects.dart';
import '../client.dart';
import '../../discord.dart';

/// Sent when a member joins a guild.
class GuildMemberAddEvent {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/events/GuildMemberRemoveEvent.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';
import '../client.dart';

/// Sent when a user leaves a guild, can be a leave, kick, or ban.
Expand Down
3 changes: 1 addition & 2 deletions lib/src/events/GuildMemberUpdateEvent.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '../../objects.dart';
import '../client.dart';
import '../../discord.dart';

/// Sent when a member is updated.
class GuildMemberUpdateEvent {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/events/GuildUpdateEvent.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '../../objects.dart';
import '../client.dart';
import '../../discord.dart';

/// Sent when a guild is updated.
class GuildUpdateEvent {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/events/MessageDeleteEvent.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '../../objects.dart';
import '../client.dart';
import '../../discord.dart';

/// Sent when a message is deleted.
class MessageDeleteEvent {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/events/MessageEvent.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '../../objects.dart';
import '../client.dart';
import '../../discord.dart';

/// Sent when a new message is received.
class MessageEvent {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/events/MessageUpdateEvent.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '../../objects.dart';
import '../client.dart';
import '../../discord.dart';

/// Sent when a message is updated.
class MessageUpdateEvent {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/events/ReadyEvent.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '../../objects.dart';
import '../client.dart';
import '../../discord.dart';

/// Sent when the client is ready.
class ReadyEvent {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/events/TypingEvent.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '../../objects.dart';
import '../client.dart';
import '../../discord.dart';

/// Sent when a user starts typing.
class TypingEvent {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/events/WebSocketErrorEvent.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '../../objects.dart';
import '../client.dart';
import '../../discord.dart';

/// Sent when the websocket encounters an error (but certian errors will throw
/// an exception).
Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/Attachment.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';

/// A message attachment.
class Attachment {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/ClientOAuth2Application.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';

/// The client's OAuth2 app, if the client is a bot.
class ClientOAuth2Application {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/ClientOptions.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';

/// The options for `Client`.
class ClientOptions {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/ClientUser.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';

/// The client user.
class ClientUser {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/Embed.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';

/// A message embed.
class Embed {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/EmbedProvider.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';

/// A message embed provider.
class EmbedProvider {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/EmbedThumbnail.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';

/// A message embed thumbnail.
class EmbedThumbnail {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/objects/Guild.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:convert';
import '../client.dart';
import '../../objects.dart';
import '../../discord.dart';
import 'package:http/http.dart' as http;

/// A guild.
Expand Down
3 changes: 1 addition & 2 deletions lib/src/objects/GuildChannel.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:convert';
import '../client.dart';
import '../../objects.dart';
import '../../discord.dart';
import 'package:http/http.dart' as http;

/// A guild channel.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/Invite.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';

/// An invite.
class Invite {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/InviteChannel.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';

/// A mini channel object for invites.
class InviteChannel {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/InviteGuild.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';

/// A mini guild object for invites.
class InviteGuild {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/Member.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';

/// A guild member.
class Member {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/objects/Message.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:convert';
import '../client.dart';
import '../../objects.dart';
import '../../discord.dart';
import 'package:http/http.dart' as http;

/// A message.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/MessageOptions.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';

/// The options for message sending.
class MessageOptions {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/OAuth2Application.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';

/// An OAuth2 application.
class OAuth2Application {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/OAuth2Guild.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';

/// A mini guild object with permissions for [OAuth2Info].
class OAuth2Guild {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/OAuth2Info.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';

/// Info about a OAuth2 app, bot, user, and possible guilds that that bot can
/// be invited to.
Expand Down
3 changes: 1 addition & 2 deletions lib/src/objects/PrivateChannel.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '../../objects.dart';
import '../client.dart';
import '../../discord.dart';

/// A private channel.
class PrivateChannel {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/objects/User.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../objects.dart';
import '../../discord.dart';

/// A user.
class User {
Expand Down
Loading

0 comments on commit 0696865

Please sign in to comment.