summaryrefslogtreecommitdiff
path: root/cowsay_weechat/cowsay.lua
blob: 03228d270f4ed5e6204911bb8add276f83393d7e (plain) (blame)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
--[[
cowsay.lua - say and show ascii art

Prerequisites
  The Lua plugin for weechat must be installed and enabled

Usage:
	/cowsay - without params will show all commands avalible
	/cowsay nerd [ARG1] - show nerd with name ARG1
	/cowsay goat [ARG1] - show goat saying ARG1
	/cowsay shoot [ARG1] - show shooting at lying ARG1
	/cowsay juice [ARG1] [ARG2] - show juice box with first line ARG1 and
second line ARG2

]]

--------------------------------------------------------------------------------
-- my drawing
function ascii_nerd( name )
	local s = ""
	s = s .. [[
\ | | /
| o o |
 \ O /
  | |
]]
	local l = string.len(name)
	for i=1,l+4 do s = s .. "+" end
	s = s .. "\n| " .. name .. " |\n"
	for i=1,l+4 do s = s .. "+" end
	return s
end

--------------------------------------------------------------------------------
--from beej.us
function ascii_goat( text )
	local s = ""
	s = s .. [[    )_)
 ___|oo) ]]
	s = s .. text .. "\n"
	s = s .. [['|  |\_|                            
 |||| #
 ````]]
	return s
end

--------------------------------------------------------------------------------
--http://ascii.co.uk/art/shoot
function ascii_shoot( name )
	local s = ""
	if name == nil then name = "" else
	name = "("..name..")" end
	s = s .. [[
   O
  <\==-   -   - -   -  -  - ---
 ./ \                            _/\_\O ]] .. name .. [[
]]
	return s
end

--------------------------------------------------------------------------------
--http://ascii.co.uk/art/juice
function ascii_juice( name1, name2 )
	local s = ""
	if name1 == nil then name1 = "" end
	if name2 == nil then name2 = "" end
	local l1 = string.len( name1 )
	local l2 = string.len( name2 )

	if l1 > 5 then 
		name1 = string.sub( name1, 1, 5 )
	elseif l1 < 5 then
		while string.len(name1) < 5 do
			name1 = name1 .. ' '
		end
	end

	if l2 > 5 then
		name2 = string.sub( name2, 1, 5 )
	elseif l2 < 5 then
		while string.len( name2 ) < 5 do
			name2 = name2 .. ' '
		end
	end

	s = s .. [[
             __
            /.-
    ______ //
   /______'/|
   [       ]|
   [ ]] .. name1 .. [[ ]|
   [ ]] .. name2 .. [[ ]|
   [  _\_  ]|
   [  :::  ]|
   [   :'  ]/
   '-------']]
   return s
end

--------------------------------------------------------------------------------
-- http://ascii.co.uk/art/coffee
function ascii_coffee( name )
	local s = ""
	if name == nil then name = "Single Expresso" end
	if name ~= nil then name = "Single Expresso for " .. name end

s = s .. [[  .-=-.
 ,|`~'|
 `|   |  ]] .. name .. [[ 
   `~']]

   	return s
end
--------------------------------------------------------------------------------
--http://ascii.co.uk/art/pool
function ascii_pool( name )
	local s = ""
	if name == nil then name = "" end

s = s .. [[,_____,_____,    6 __
T\  :.      .^\,_/_\_I_     ]] .. name .. [[ 
I ^T=====;=====T   /|   
   I           I _|_|]]

   	return s
end
--------------------------------------------------------------------------------
--http://ascii.co.uk/art/cat
function ascii_cat( text )
	local s = ""
	if text == nil then text = "mmeeoowwrr!" end

s = s .. [[
    )   _. ]] .. text .. [[ 
   (___)''
   / ,_,/
  /'"\ )\]]
	return s
end  

function cs_print_list()
	weechat.print("","buf "..weechat.current_buffer())
	weechat.print(weechat.current_buffer(),"/msg #mainlv br br")
end

function cs_command( cmd, args )
	cmd = string.lower(cmd)
	weechat.print("",cmd..":"..args)
	if cmd == "nerd" then
		weechat.command( weechat.current_buffer(), ascii_nerd(args) )
	elseif cmd == "goat" then
		weechat.command( weechat.current_buffer(), ascii_goat(args) )
	elseif cmd == "shoot" then
		weechat.command( weechat.current_buffer(), ascii_shoot(args) )
	elseif cmd == "coffee" then
		weechat.command( weechat.current_buffer(), ascii_coffee(args) )
	elseif cmd == "pool" then
		weechat.command( weechat.current_buffer(), ascii_pool(args) )
	elseif cmd == "cat" then
		weechat.command( weechat.current_buffer(), ascii_cat(args) )
	else
		weechat.print(weechat.current_buffer(), "Unknown command")
	end
end

--
-- Main entry point
--
function cowsay_init(data, buffer, args)
	local cmd, params = string.match(args, "(%a+)%s*(.*)")
	if not cmd or cmd == "" then
		cs_print_list()
		return weechat.WEECHAT_RC_OK
	end

	cs_command( cmd, params )

	return weechat.WEECHAT_RC_OK
end


--
-- Register with weechat
--
weechat.register("cowsay", "FreeArtMan", "0.0.1", "Beerware", "ASCII drawing in commanline", "", "")
weechat.hook_command("cowsay", 
	"cowsay",  -- description
	"[shoot <name>, goat <name>, juice <line1> <line2>, nerd <name>, coffee <text>, pool <name>, cat <text>", -- args
	"  list: \n"..
	"  add: \n"..
	"  del: \n\n"..
	"If no command is given, all phrases are listed.",
	"nerd|juice|goat|shoot|coffee|pool|, -- completion
	"cowsay_init", 
	"")