+
+#
+# Handle a received message.
+# Create an event structure and hand it off to libvideosite
+#
+sub message_hook {
+ my ($data, $buffer, $date, $tags, $displayed, $highlight, $prefix, $message ) = @_;
+ my %event = (
+ message => $message,
+ ewpf => sub { weechat::print($buffer, @_) },
+ );
+
+ libvideosite::check_for_link(\%event);
+
+ return weechat::WEECHAT_RC_OK;
+}
+
+#
+# Reset the plugin
+#
+sub videosite_reset {
+ unless(libvideosite::register_api({
+ io => sub { weechat::print("", @_) },
+ config_init => sub {},
+ config_get => \&config_get,
+ config_set => \&config_set,
+ config_has => \&config_has,
+ config_save => sub { 1 },
+ config_del => \&config_del,
+ color => \&colorpair,
+ module_path => sub { return File::Spec->catfile(weechat::info_get("weechat_dir", ""), 'perl') },
+ quote => sub { return $_ },
+ reload => sub { weechat::print("", "Please use \"/script reload ...\" to reload") },
+ })) {
+ weechat::print("", sprintf("videosite API register failed: %s", $libvideosite::error));
+ return 0;
+ }
+
+ unless(libvideosite::init()) {
+ weechat::print("", sprintf("videosite init failed: %s", $libvideosite::error));
+ return 0;
+ }
+
+ return 1;
+}
+
+sub videosite_init {
+ # Find out the script directory, and add it to @INC.
+ # This is necessary to find libvideosite.pm
+
+ push(@INC, File::Spec->catfile(weechat::info_get("weechat_dir", ""), 'perl'));
+ load 'libvideosite';
+
+ if (videosite_reset()) {
+ weechat::hook_print("", "notify_message", "://", 1, "message_hook", "");
+ weechat::hook_print("", "notify_private", "://", 1, "message_hook", "");
+ weechat::hook_print("", "notify_highlight", "://", 1, "message_hook", "");
+ weechat::hook_print("", "notify_none", "://", 1, "message_hook", "");
+ weechat::hook_command( "videosite", "videosite control functions", "", "", "", "videosite_hook", "");
+ }
+}
+
+videosite_init();