1 # shim to connect libvideosite to xchat2
3 # (c) 2007-2013 by Ralf Ertzinger <ralf@camperquake.de>
4 # licensed under GNU GPL v2
12 # List of foreground colors. This list is not complete, it just
13 # contains the colors needed by videosite.
15 my %foreground_colors = (
16 'magenta' => "\x0313",
17 '*magenta' => "\x0313\x02",
18 '*yellow' => "\x038\x02",
19 '*green' => "\x039\x02",
20 '*red' => "\x035\x02",
25 # A hash to hold the config
32 "videosite Video URL grabber script (usage: /videosite)");
35 # Return a color code. Called by the core
37 # Does not handle background colors yet.
42 $fg = exists($foreground_colors{$fg})?$foreground_colors{$fg}:'';
49 # Handle commands (/videosite ...)
52 my (undef, $msg) = @_;
54 my $context = Xchat::get_context();
59 my $oldcxt = Xchat::get_context();
60 Xchat::set_context($context);
62 Xchat::set_context($oldcxt);
64 window => sprintf("%s/%s", Xchat::get_info('server'), Xchat::get_info('channel')),
67 libvideosite::handle_command(\%event);
69 return Xchat::EAT_XCHAT;
73 # Handle a received message.
74 # Create an event structure and hand it off to libvideosite
79 my $context = Xchat::get_context();
84 my $oldcxt = Xchat::get_context();
85 Xchat::set_context($context);
87 Xchat::set_context($oldcxt);
89 window => sprintf("%s/%s", Xchat::get_info('server'), Xchat::get_info('channel')),
92 libvideosite::check_for_link(\%event);
93 return Xchat::EAT_NONE;
100 unless(libvideosite::register_api({
101 io => sub { Xchat::print(@_) },
102 _config_path => sub { return File::Spec->catfile(Xchat::get_info("xchatdir")) },
103 color => \&colorpair,
104 module_path => sub { return File::Spec->catfile(Xchat::get_info("xchatdir"), 'perl') },
105 quote => sub { return $_ },
106 reload => \&videosite_reset,
108 Xchat::print("", sprintf("videosite API register failed: %s", $libvideosite::error));
112 unless(libvideosite::init()) {
113 Xchat::print("", sprintf("videosite init failed: %s", $libvideosite::error));
121 # Find out the script directory, and add it to @INC.
122 # This is necessary to find libvideosite.pm
124 push(@INC, File::Spec->catfile(Xchat::get_info("xchatdir"), 'perl'));
127 if (videosite_reset()) {
128 foreach ('Channel Message', 'Your Message') {
129 Xchat::hook_print($_, \&message_hook);
131 Xchat::hook_command('videosite', \&videosite_hook);