From a2cc6b3f56e144bdc8927364b6d394150d94bdb9 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sun, 17 Apr 2022 18:36:10 -0300 Subject: Add some more examples --- src/lib.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index a2b43b3..3211786 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1256,6 +1256,16 @@ impl<'a, 'ph: 'a> ValidContext<'a, 'ph> { } /// Executes a command. + /// + /// # Examples + /// + /// ```no_run + /// use hexchat_unsafe_plugin::{ValidContext}; + /// + /// fn join(context: ValidContext<'_, '_>, channel: &str) { + /// context.command(&format!("join {}", channel)); + /// } + /// ``` pub fn command(self, cmd: &str) { let ph = self.ph; // need to put this in a more permanent position than temporaries @@ -1265,6 +1275,18 @@ impl<'a, 'ph: 'a> ValidContext<'a, 'ph> { } } + /// Prints an event message, and returns a success status (whether or not + /// the event exists). + /// + /// # Examples + /// + /// ```no_run + /// use hexchat_unsafe_plugin::{ValidContext}; + /// + /// fn emit_channel_message(context: ValidContext<'_, '_>, nick: &str, msg: &str) { + /// context.emit_print("Channel Message", [nick, msg]); + /// } + /// ``` pub fn emit_print<'b, I: IntoIterator>(self, event: &str, args: I) -> bool { let ph = self.ph; let event = CString::new(event).unwrap(); @@ -1291,6 +1313,23 @@ impl<'a, 'ph: 'a> ValidContext<'a, 'ph> { } } + /// Prints an event message, and returns a success status (whether or not + /// the event exists). + /// + /// Also allows setting event attributes. + /// + /// # Examples + /// + /// ```no_run + /// use std::time::SystemTime; + /// use hexchat_unsafe_plugin::{EventAttrs, ValidContext}; + /// + /// fn emit_channel_message_at(context: ValidContext<'_, '_>, time: Option, nick: &str, msg: &str) { + /// let mut attrs = EventAttrs::new(); + /// attrs.server_time = time; + /// context.emit_print_attrs(attrs, "Channel Message", [nick, msg]); + /// } + /// ``` pub fn emit_print_attrs<'b, I: IntoIterator>(self, attrs: EventAttrs, event: &str, args: I) -> bool { let ph = self.ph; let event = CString::new(event).unwrap(); -- cgit 1.4.1