Project

General

Profile

Actions

Support #4036

closed

embedd pictures / videos / ...

Added by Stefan R almost 6 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Plugin
Target version:
Start date:
07/15/2018
Due date:
% Done:

0%

Estimated time:
Operative System:
Windows 10

Description

Hi there,

I want to write a plugin which is embedding some images based on messages which are received. Is there any option to embedd a picture or even a video using 'OnChannelNormalMessage' and 'OnChannelNormalMessage'?

Would be great if there is something (like that what is used by the image preview settinge?!?).

Actions #1

Updated by Per Amundsen almost 6 years ago

Videos is of course not possible, AdiIRC does not use a browser window for text, it's a custom made from scratch text view, but it does support gifs/images and emoticons.

You can add any image/gif to the buffer using the /inlineimage command, it's usable from plugins as well through the IWIndow.ExecuteCommand API.

Hope that helps.

Actions #2

Updated by Stefan R almost 6 years ago

I am sorry but I am having some troubles putting an image into the corresponding private message or channel message window. Can you help me please? Currently I try this (c#.net plugin):

private void PluginHost_OnPrivateNormalMessage(AdiIRCAPIv2.Arguments.PrivateMessages.PrivateNormalMessageArgs argument) {
// ?? no idea how to do /inlineimage into the private windows i receive the text
// what i need: embedd a picture in the private message window where the massage was fired from
}

private void PluginHost_OnChannelNormalMessage(AdiIRCAPIv2.Arguments.ChannelMessages.ChannelNormalMessageArgs argument) {
// this is always been embedded in the current active windows. So if i am in a private message and a channel message is received
// i get the picture embedded in the current active window
// what i need: embedd a picture in the channel message windows where the message was fired from
argument.Channel.ExecuteCommand("/inlineimage -a https://www.google.de/logos/doodles/2018/world-cup-2018-day-25-5662299103690752.2-law.gif");
}

Actions #3

Updated by Per Amundsen almost 6 years ago

You need to add the [window] parameter to the /inlineimage command instead of using "-a" for active window, in this case you want the [window] to be the channel name which you can get from ChannelNormalMessageArgs.Channel.Name.

Example:

private void PluginHost_OnChannelNormalMessage(AdiIRCAPIv2.Arguments.ChannelMessages.ChannelNormalMessageArgs argument) {
argument.Channel.ExecuteCommand("/inlineimage " + argument.Channel.Name + " https://www.google.de/logos/doodles/2018/world-cup-2018-day-25-5662299103690752.2-law.gif");
}
Actions #4

Updated by Stefan R almost 6 years ago

Ah thx, that is working fine now! One last thing, is it possible to place the inline after the message? Because now it is always printing the image above the message.

Actions #5

Updated by Per Amundsen almost 6 years ago

I just realized there is no reference to the IPrivateWindow in the PrivateNormalMessageArgs, that is an oversight and I will fix that, currently checking if there is an alternative.

But for your use case, you should be able to use this for now.

private void PluginHost_OnPrivateNormalMessage(AdiIRCAPIv2.Arguments.PrivateMessages.PrivateNormalMessageArgs argument) {
host.ActiveIWindow.ExecuteCommand("/inlineimage " + argument.User.Nick + " https://www.google.de/logos/doodles/2018/world-cup-2018-day-25-5662299103690752.2-law.gif");
}

Ah thx, that is working fine now! One last thing, is it possible to place the inline after the message? Because now it is always printing the image above the message.

The OnChannelNormalMessage is fired before the regular message is added to the text buffer, so your image is inserted before the message, there is an -iN parameter to insert at a specific line, but that wouldn't help in this case.

Maybe you could use a System.Windows.Forms.Timer to break free from the current event? E.g even if it set to trigger after 1 millisecond, it would allow adiirc to process the channel message before the timer triggers.

Actions #6

Updated by Per Amundsen almost 6 years ago

Here is what I came up with for getting the private window.

private void PluginHost_OnPrivateNormalMessage(AdiIRCAPIv2.Arguments.PrivateMessages.PrivateNormalMessageArgs argument) {
    IPrivateWindow privateWindow = GetPrivateWindow(argument.User.Nick);
    if (privateWindow != null) {
        privateWindow.ExecuteCommand("/inlineimage " + argument.User.Nick + " https://www.google.de/logos/doodles/2018/world-cup-2018-day-25-5662299103690752.2-law.gif");
    }
}

private IPrivateWindow GetPrivateWindow(string nick)
{
    foreach (IWindow window in this.Host.GetWindows)
    {
        IPrivateWindow privateWindow = window as IPrivateWindow;
        if (privateWindow != null && privateWindow.Name == nick)
        {
            return privateWindow;
        }
    }

    return null;
}
Actions #7

Updated by Stefan R almost 6 years ago

My code at the moment is this and it is working fine (i am using a windows form to make use of begininvoke which should execute the inlineimage as soon as the process finished sending the message):

namespace Testplugin
{
    using AdiIRCAPIv2.Interfaces;
    using System.Reflection;
    using System;
    using System.Linq;
    using System.Windows.Forms;

    public class Testplugin : IPlugin
    {
        private IPluginHost _host = null;
        private Form _frm = new Form();

        public delegate void InvokeDelegate(string name, string image);

        public string PluginName
        {
            get
            {
                System.Diagnostics.Debugger.Launch();
                return "Testplugin";
            }
        }

        public string PluginDescription
        {
            get
            {
                return "A simple Testplugin";
            }
        }

        public string PluginAuthor
        {
            get
            {
                return "Testplugin user";
            }
        }

        public string PluginVersion
        {
            get
            {
                return Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }
        }

        public string PluginEmail
        {
            get
            {
                return "noreply@domain.tld";
            }
        }

        public void Dispose()
        {

        }

        public void Initialize(IPluginHost pluginHost)
        {
            _frm.Size = new System.Drawing.Size(0, 0);
            _frm.Location = new System.Drawing.Point(int.MinValue);
            _frm.ShowInTaskbar = false;
            _frm.FormBorderStyle = FormBorderStyle.None;
            _frm.Show();
            _frm.Hide();

            _host = pluginHost;

            pluginHost.OnChannelNormalMessage += PluginHost_OnChannelNormalMessage;
            pluginHost.OnPrivateNormalMessage += PluginHost_OnPrivateNormalMessage;
            pluginHost.OnMessageSent += PluginHost_OnMessageSent;
        }

        private void PluginHost_OnMessageSent(AdiIRCAPIv2.Arguments.Contextless.MessageSentArgs argument)
        {
            _frm.BeginInvoke(new InvokeDelegate(SendInlineImage), argument.Target, "https://www.google.de/logos/doodles/2018/world-cup-2018-day-25-5662299103690752.2-law.gif");
        }

        private void PluginHost_OnPrivateNormalMessage(AdiIRCAPIv2.Arguments.PrivateMessages.PrivateNormalMessageArgs argument)
        {
            _frm.BeginInvoke(new InvokeDelegate(SendInlineImage), argument.User.Nick, "https://www.google.de/logos/doodles/2018/world-cup-2018-day-25-5662299103690752.2-law.gif");
        }

        private void PluginHost_OnChannelNormalMessage(AdiIRCAPIv2.Arguments.ChannelMessages.ChannelNormalMessageArgs argument)
        {
            _frm.BeginInvoke(new InvokeDelegate(SendInlineImage), argument.Channel.Name, "https://www.google.de/logos/doodles/2018/world-cup-2018-day-25-5662299103690752.2-law.gif");
        }

        private void SendInlineImage(string name, string image)
        {
            _host.ActiveIWindow.ExecuteCommand(string.Format("inlineimage {0} {1}", name, image));
        }
    }
}

Actions #8

Updated by Per Amundsen almost 6 years ago

Oh yeah, great idea.

Btw I think you can get the mainform form using Form frm = (Form)Control.FromHandle(_host.MainWindowHandle);

Not sure if that makes a difference for invoking.

Actions #9

Updated by Stefan R almost 6 years ago

Don't know if this makes a difference but I try my solution now and if there is an error or something like that I try your last idea. But thx!

Actions #10

Updated by Per Amundsen almost 6 years ago

  • Status changed from New to Closed

Np.

Actions

Also available in: Atom PDF