Script: emote.scm

Replace keywords with emoticons.
Author: csmith — Version: 0.3.1 — License: GPL-3.0-or-later
For WeeChat ≥ 0.4.1.
Tags: emoticon
Added: 2015-03-22 — Updated: 2023-03-22

Download GitHub Repository

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
; Copyright (c) 2014 by csmith <caleb.smithnc@gmail.com>
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program.  If not, see <http://www.gnu.org/licenses/>.
;
;
; (this script requires WeeChat 0.4.1 or newer)
;
; History:
; 2023-03-18, Yuval Langer <yuval.langer@gmail.com>
;   version 0.3.1: Replace `apply string-append` with `string-join`.
; 2017-02-18, nycatelos <nycatelos@riseup.net>
;   version 0.3: added more emotes
; 2016-06-03, nycatelos <nycatelos@riseup.net>
;   version 0.2: added additional emotes
; 2014-05-03, csmith <caleb.smithnc@gmail.com>
;   version 0.1: initial release

(use-modules (srfi srfi-69))

(weechat:register "emote" "Caleb Smith" "0.3.1" "GPL" "Emote" "" "")

; Mappings of words with their emoticons
(define patterns (alist->hash-table '(
    ("tableflip" . "(╯° °)╯︵ ┻━┻)")
    ("rageflip" . "(ノಠ益ಠ)ノ彡┻━┻")
    ("doubleflip" . "┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻")
    ("disapproval" . "ಠ_ಠ")
    ("sun" . "☼")
    ("kitaa" . "キタ━━━(゜∀゜)━━━!!!!!")
    ("joy" . "◕‿◕")
    ("nyancat" . "~=[,,_,,]:3")
    ("lenny" . "( ͡° ͜ʖ ͡°)")
    ("shrug" . \\_(ツ)_/¯")
    ("denko" . "(・ω・)")
    ("tableplace" . "┬─┬ ノ( ゜-゜ノ)")
    ("gface" . "( ≖‿≖)")
    ("facepalm" . "(-‸ლ)")
    ("tehe" . "☆~(◡﹏◕✿)")
    ("angry" . "(╬ ಠ益ಠ)")
    ("umu" . "( ̄ー ̄)")
    ("toast" . "( ^_^)o自自o(^_^ )")
    ("yay" . "ヽ(´ー`)ノ")

)))


; Derive the tab completion string for the subcommands.
(define tab-completions
    (string-join
        (map (lambda (i) (string-append "|| " i))
            (hash-table-keys patterns))))


; Hook main function up to the /emote command
(weechat:hook_command
    "emote" "Emote" "/emote phrase"
    (string-append
        ""
        "\nUse `/emote phrase`. Words in phrase will be replaced with their"
        "\nemoticons:"
        "\n"
        "\nExamples:"
        "\n    /emote tableflip - (╯° °)╯︵ ┻━┻)"
        "\n    /emote look - ಠ_ಠ")
    tab-completions
    "main" "")


; Handle the IRC command given by the user. Sets input buffer as a side-effect
(define (main data buffer command)
    (weechat:buffer_set buffer "input"
        (string-join (map (lambda (c)
            (string-append (hash-table-ref/default patterns c c) " "))
            (string-tokenize command))))
    weechat:WEECHAT_RC_OK)