Skip to content

Instantly share code, notes, and snippets.

@matheusfillipe
Last active June 8, 2022 21:20
Show Gist options
  • Save matheusfillipe/ce465e52b7442a4fb712362f25ffcce2 to your computer and use it in GitHub Desktop.
Save matheusfillipe/ce465e52b7442a4fb712362f25ffcce2 to your computer and use it in GitHub Desktop.
Irc client in dart with null safety
import 'dart:convert';
import "package:irc/client.dart";
import "dart:io";
// This stores our configuration for this client
var config = Configuration(
host: "irc.dot.org.es",
port: 6697,
ssl: true,
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("#romanian");
});
client.onClientJoin.listen((event) async {
var lines = stdin.transform(utf8.decoder).transform(const LineSplitter());
// Loop sending messages
stdout.write(">> ");
await for (final l in lines) {
client.sendMessage("#romanian", l);
stdout.write(">> ");
}
});
// 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}");
stdout.write(">> ");
});
// Connect to the server
await client.connect();
}
name: irctest
description: A sample command-line application.
version: 1.0.0
# homepage: https://www.example.com
environment:
sdk: '>=2.17.0 <3.0.0'
dependencies:
irc:
git:
url: https://github.com/ostafen/irc.dart
ref: flutter
dev_dependencies:
lints: ^2.0.0
test: ^1.16.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment