irc 4.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 63

Dart IRC Build Status Latest Version #

Simple Dart library for IRC.

Getting Started #

Visit the Getting Started wiki page.

Notices #

irc.dart is licensed under the MIT license. We really don't care what you do. Use it and abuse it.

4.0.1 #

  • Fix pub analysis issues

4.0.0 #

  • First version to support Dart v2
  • Added pedantic for analysis issues
  • Fixed all pedantic issues

example/main.dart

import 'dart:async';
import 'dart:math';

import 'package:irc/client.dart';

typedef CommandHandler(CommandEvent event);

final Random random = Random();

String prefix = '~';
Map<String, StreamController<CommandEvent>> commands = {};

void main() {
  var nickOffset = random.nextInt(9999);
  var config = new Configuration(
      host: 'irc.freenode.net',
      port: 6667,
      nickname: "DartBot$nickOffset",
      username: "DartBot$nickOffset",
      realname: 'DartBot');

  var client = new Client(config);
  client.connect();

  client.onLineSent.listen((event) {
    print("<< ${event.line}");
  });

  client.onLineReceive.listen((event) {
    print(">> ${event.line}");
  });

  client.onDisconnect.listen((e) async {
    await new Future.delayed(const Duration(seconds: 1));
    client.connect();
  });

  client.onMode.listen((event) {
    if (event.channel != null && event.user != null) {
      print(
          "Mode (${event.mode}) given to ${event.user} in ${event.channel.name}");
    } else if (event.channel != null) {
      print("Mode (${event.mode}) given to ${event.channel.name}");
    } else if (event.user != null) {
      print("Mode (${event.mode}) was set on us.");
    }
  });

  client.onReady.listen((event) {
    event.join("#spinlocklabs");

    if (client.monitor.isSupported) {
      client.monitor.add("kaendfinger");
    }
  });

  client.register(handleAsCommand);

  command("notice-me", (CommandEvent event) {
    event.notice("This is a test notice to you");
  });

  command("server-caps", (CommandEvent e) {
    e.reply("Supported: ${client.supported}");
    e.reply("Capabilities: ${client.serverCapabilities.join(', ')}");
  });

  command("notice-chan", (CommandEvent event) {
    event.notice("This is a test notice to the channel", user: false);
  });

  command("join", (CommandEvent event) {
    if (event.args.length == 1) {
      client.join(event.args[0]);
    } else {
      event.reply("Usage: join <channel>");
    }
  });

  command("part", (CommandEvent event) {
    if (event.args.length == 1) {
      client.part(event.args[0]);
    } else if (event.args.isEmpty) {
      client.part(event.channel.name);
    } else {
      event.reply("Usage: part [channel]");
    }
  });

  command("quit", (CommandEvent event) {
    client.disconnect(reason: "${event.from.name} asked me to quit.");
  });

  command("topic", (CommandEvent event) {
    event.reply(event.channel.topic);
  });

  command("bans", (CommandEvent event) {
    event.reply("${event.channel.bans}");
  });

  command("spam", (CommandEvent event) {
    for (var i = 1; i <= 50; i++) {
      event.reply(i.toString());
    }
  });

  command("users", (CommandEvent event) {
    String joinNicks(Set<User> users) {
      if (users.length > 10) {
        return "${users.length} users";
      }
      return users
          .map((it) {
            return it.nickname;
          })
          .toList()
          .join(", ");
    }

    if (!event.target.isChannel) {
      return;
    }

    Channel channel = event.target;
    if (event.args.isNotEmpty) {
      channel = client.getChannel(event.args[0]);
    }

    if (channel == null) {
      event.notice("${event.args[0]} not found.");
      return;
    }

    event.notice("> Members: ${joinNicks(channel.members)}");
    event.notice("> Ops: ${joinNicks(channel.ops)}");
    event.notice("> Voices: ${joinNicks(channel.voices)}");
    event.notice("> Owners: ${joinNicks(channel.owners)}");
    event.notice("> Half-Ops: ${joinNicks(channel.halfops)}");
    event.notice("> All Users: ${joinNicks(channel.allUsers)}");
  });

  command("act", (CommandEvent event) {
    event.act("is silleh.");
  });

  command("whois", (CommandEvent event) async {
    if (event.args.length != 1) {
      event.reply("Usage: whois <user>");
      return;
    }

    var whois = await client.whois(event.args[0]);
    var info = whois.toString();
    event.notice(info);
  });

  command("away", (CommandEvent event) async {
    if (event.args.length == 1) {
      User user = client.getUser(event.args[0]);
      var isAway = await user.isAway();
      if (isAway) {
        event.reply("${user.name} is away.");
      } else {
        event.reply("${user.name} is not away.");
      }
    }
  });

  command("server-version", (CommandEvent e) async {
    var version = await client.getServerVersion();
    e.reply("Server: ${version.server}, Version: ${version.version}");
  });

  command("online", (CommandEvent e) {
    if (e.args.length != 1) {
      return;
    }

    e.reply("Online: ${client.monitor.isUserOnline(e.args[0])}");
  });
}

void handleAsCommand(MessageEvent event) {
  String message = event.message;

  if (message.startsWith(prefix)) {
    var end = message.contains(" ")
        ? message.indexOf(" ", prefix.length)
        : message.length;
    var command = message.substring(prefix.length, end);
    var args =
        message.substring(end != message.length ? end + 1 : end).split(" ");

    args.removeWhere((i) => i.isEmpty || i == " ");

    if (commands.containsKey(command)) {
      commands[command].add(new CommandEvent(event, command, args));
    } else {
      commandNotFound(new CommandEvent(event, command, args));
    }
  }
}

void command(String name, CommandHandler handler) {
  commands
      .putIfAbsent(name, () {
        return new StreamController.broadcast();
      })
      .stream
      .listen((e) async {
        try {
          await handler(e);
        } catch (e, stack) {
          print(e);
          print(stack);
        }
      }, onError: (e, stack) {
        print(e);
        print(stack);
      });
}

void commandNotFound(CommandEvent event) {
  event.reply("Command not found.");
}

class CommandEvent extends MessageEvent {
  String command;
  List<String> args;

  CommandEvent(MessageEvent event, this.command, this.args)
      : super(event.client, event.from, event.target, event.message);

  void notice(String message, {bool user = true}) =>
      client.sendNotice(from.name, message);

  void act(String message) => client.sendAction(target.name, message);

  String argument(int index) => args[index];
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  irc: ^4.0.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:irc/client.dart';
import 'package:irc/event.dart';
import 'package:irc/parser.dart';
import 'package:irc/protocol.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
41
Health:
Code health derived from static analysis. [more]
75
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
63
Learn more about scoring.

We analyzed this package on Jul 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Analysis suggestions

Package not compatible with SDK flutter

Because it is not compatible with any of the supported runtimes: flutter-native, flutter-web

Package not compatible with runtime flutter-native on android

Because of the import of dart:mirrors via the import chain package:irc/client.dartpackage:irc/event.dartdart:mirrors

Package not compatible with runtime flutter-native on ios

Because of the import of dart:mirrors via the import chain package:irc/client.dartpackage:irc/event.dartdart:mirrors

Package not compatible with runtime flutter-native on linux

Because of the import of dart:mirrors via the import chain package:irc/client.dartpackage:irc/event.dartdart:mirrors

Package not compatible with runtime flutter-native on macos

Because of the import of dart:mirrors via the import chain package:irc/client.dartpackage:irc/event.dartdart:mirrors

Package not compatible with runtime flutter-native on windows

Because of the import of dart:mirrors via the import chain package:irc/client.dartpackage:irc/event.dartdart:mirrors

Package not compatible with runtime flutter-web on web

Because of the import of dart:mirrors via the import chain package:irc/client.dartpackage:irc/event.dartdart:mirrors

Package not compatible with runtime native-aot

Because of the import of dart:mirrors via the import chain package:irc/client.dartpackage:irc/event.dartdart:mirrors

Package not compatible with runtime web

Because of the import of dart:mirrors via the import chain package:irc/client.dartpackage:irc/event.dartdart:mirrors

Health suggestions

Fix lib/src/client/client.dart. (-25 points)

Analysis of lib/src/client/client.dart reported 95 hints, including:

line 14 col 38: Unnecessary new keyword.

line 72 col 40: Unnecessary new keyword.

line 75 col 19: Unnecessary new keyword.

line 76 col 19: Unnecessary new keyword.

line 83 col 15: Unnecessary new keyword.

Fix lib/src/client/channel.dart. (-4.41 points)

Analysis of lib/src/client/channel.dart reported 9 hints, including:

line 16 col 25: Unnecessary new keyword.

line 19 col 29: Unnecessary new keyword.

line 22 col 28: Unnecessary new keyword.

line 25 col 29: Unnecessary new keyword.

line 28 col 28: Unnecessary new keyword.

Fix lib/src/event/core.dart. (-3.93 points)

Analysis of lib/src/event/core.dart reported 8 hints, including:

line 37 col 21: Unnecessary new keyword.

line 61 col 13: Unnecessary new keyword.

line 110 col 13: Unnecessary new keyword.

line 135 col 15: Unnecessary new keyword.

line 144 col 15: Unnecessary new keyword.

Fix additional 10 files with analysis or formatting issues. (-13.89 points)

Additional issues in the following files:

  • lib/src/parser/message.dart (7 hints)
  • lib/src/client/base.dart (6 hints)
  • lib/src/client/connection.dart (3 hints)
  • lib/src/parser/regex.dart (3 hints)
  • lib/src/client/colors.dart (2 hints)
  • lib/src/client/user.dart (2 hints)
  • lib/src/parser/hostmask.dart (2 hints)
  • lib/src/client/helpers.dart (1 hint)
  • lib/src/client/pool.dart (1 hint)
  • lib/src/parser/base.dart (1 hint)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
glob ^1.1.7 1.2.0
pedantic ^1.5.0 1.9.0 1.9.1
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.13
js 0.6.2
meta 1.1.8
node_interop 1.1.1
node_io 1.1.1
path 1.7.0
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
Dev dependencies
test ^1.3.2