[go: up one dir, main page]

Skip to content
chris edited this page Apr 26, 2021 · 13 revisions

Adding the Dependency

irc.dart v4.0.0 is the first version to be Dart 2 compatible.

Add the following to your pubspec.yaml

dependencies:
  irc: "^4.0.0"

After that, run dart pub get

Use the Library

From v3.0.0, irc.dart now supports user objects, which are global across the client. This means you don't have to deal with nicknames anymore.

import "package:irc/client.dart";

// This stores our configuration for this client
var config = Configuration(host: "irc.esper.net", port: 6667, nickname: "DartBot", username: "DartBot");
// "Primary" IRC class
var client = Client(config);

main() async {
  // Register an onReady event handler
  client.onReady.listen((event) {
    // Join a channel
    event.join("#your-channel");
  });

  // Register an onMessage event handler    
  client.onMessage.listen((event) {
    // Log any message events to the console
    print("<${event.target.name}><${event.from.name}> ${event.message}");
  });

  // Connect to the server
  client.connect();
}
Clone this wiki locally