-
Notifications
You must be signed in to change notification settings - Fork 0
/
Todo.ps1
executable file
·248 lines (220 loc) · 7.57 KB
/
Todo.ps1
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#Write-Host "Starting Todo"
function Get-Item-Color($item)
{
if ($item.hasFailed -eq "1")
{
#fail
return (ColorCode white red )
}
else
{
if ($item.completedBy -ne "")
{
#completed but not failed
return (ColorCode white green)
}
elseif($item.takenBy -ne "")
{
#not complted byt taken
return (ColorCode white blue)
}
else
{
#not taken
return (ColorCode white black)
}
}
}
function Print-Todo()
{
$i = 0
$todo = Get-List TodoList.txt
(ColorCode white black) + (Repeat-String "*" 57)
ForEach($item in $todo)
{
$length = [int]50 - [int]$item.task.length
$color = Get-Item-Color($item)
$color + "* " + ($i) + ": " + $item.task + (Repeat-String " " $length) + " *"
$i = $i+1
}
(ColorCode white black ) + (Repeat-String "*" 57)
}
function Add-Todo($Task)
{
$file = "C:\ps1\irc\TodoList.txt"
$xml = New-Object XML
$xml.Load($file)
$oldItem = @($xml.list.item)[0]
$newItem = $oldItem.Clone()
$newItem.task = $Task.Replace("_", " ")
$newItem.hasFailed = "0"
$newItem.takenBy = ""
$newItem.completedBy = ""
$newItem.completedOn = ""
$newItem = $xml.list.appendChild($newItem)
$xml.Save($file)
"Added $Task"
}
function Take-Todo($TaskId, $User)
{
$file = "C:\ps1\irc\TodoList.txt"
$xml = New-Object XML
$xml.Load($file)
$oldItem = @($xml.list.item)[[int]$TaskId]
if($oldItem -eq $null)
{
"Invalid Task"
}
else
{
if($oldItem.takenBy -eq "")
{
$newItem = $oldItem.Clone()
$newItem.takenBy = [string]$User
$newItem = $xml.list.ReplaceChild($newItem, $oldItem)
$xml.Save($file)
"You've taken task: " + ($TaskId) + ": " + $newItem.task
}
else
{
$oldItem.takenBy + " has beat you to the punch"
}
}
}
function Insert-Todo($Task, $Before)
{
$file = "C:\ps1\irc\TodoList.txt"
$xml = New-Object XML
$xml.Load($file)
$oldItem = @($xml.list.item)[[int]$Before]
$newItem = $oldItem.Clone()
$newItem.task = $Task.Replace("_", " ")
$newItem.hasFailed = "0"
$newItem.takenBy = ""
$newItem.completedBy = ""
$newItem = $xml.list.InsertBefore($newItem, $oldItem)
$xml.Save($file)
"Inserted $Task"
}
function Mark-Todo($TaskId, $User)
{
$file = "C:\ps1\irc\TodoList.txt"
$xml = New-Object XML
$xml.Load($file)
$oldItem = @($xml.list.item)[[int]$TaskId]
if($oldItem -eq $null)
{
"Invalid Task"
}
else
{
if($oldItem.takenBy -ne $User)
{
"Only " + $oldItem.takenBy + " can complete this item"
}
elseif($oldItem.completedBy -eq "")
{
$newItem = $oldItem.Clone()
$newItem.completedBy = [string]$User
$a = Get-Date
$newItem.completedOn = $a.ToShortTimeString()
$newItem = $xml.list.ReplaceChild($newItem, $oldItem)
$xml.Save($file)
"You've completed task: " + ($TaskId) + ": " + $newItem.task
}
else
{
$oldItem.takenBy + " has beat you to the punch"
}
}
}
function Info-Todo($TaskId)
{
$file = "C:\ps1\irc\TodoList.txt"
$xml = New-Object XML
$xml.Load($file)
$item = @($xml.list.item)[[int]$TaskId]
if($item -eq $null)
{
"Invalid Task"
}
else
{
$color = Get-Item-Color($item)
(ColorCode white black) + (Repeat-String "*" 57)
$color + "* Task: " + $item.task + (Repeat-String " " (47-$item.task.Length)) + " *"
$color + "* Taken By: " + $item.takenBy + (Repeat-String " " (43-$item.takenBy.Length)) + " *"
$color + "* Has Failed: " + $item.hasFailed + (Repeat-String " " (41-$item.hasFailed.Length)) + " *"
$color + "* Failed By: " + $item.failedBy + (Repeat-String " " (42-$item.failedBy.Length)) + " *"
$color + "* Completed By: " + $item.CompletedBy + (Repeat-String " " (39-$item.CompletedBy.Length)) + " *"
$color + "* Completed At: " + $item.completedOn + (Repeat-String " " (39-$item.completedOn.Length)) + " *"
(ColorCode white black) + (Repeat-String "*" 57)
}
}
function Fail-Todo($TaskId, $User)
{
$file = "C:\ps1\irc\TodoList.txt"
$xml = New-Object XML
$xml.Load($file)
$oldItem = @($xml.list.item)[[int]$TaskId]
if($oldItem -eq $null)
{
"Invalid Task"
}
else
{
$newItem = $oldItem.Clone()
$newItem.failedBy = [string]$User
$newItem.hasFailed = "1"
$newItem = $xml.list.ReplaceChild($newItem, $oldItem)
$xml.Save($file)
"You've failed task: " + ($TaskId) + ": " + $newItem.task
}
}
function Help-Todo()
{
(ColorCode "black" "light grey") + "*********************************************************"
(ColorCode "black" "light grey") + "* Here are all the commands I respond to *"
(ColorCode "black" "grey") + "* add taskname *"
(ColorCode "black" "light grey") + "* - adds 'taskname' to the end of the list *"
(ColorCode "black" "light grey") + "* - 'taskname' must be one word or words separated by _ *"
(ColorCode "black" "light grey") + "* - Example: add Deploy_DB *"
(ColorCode "black" "light grey") + "* *"
(ColorCode "black" "grey") + "* insert taskname 1 *"
(ColorCode "black" "light grey") + "* - inserts 'taskname' before task #1 in the list *"
(ColorCode "black" "light grey") + "* - this command must have a taskname and a number *"
(ColorCode "black" "light grey") + "* - reference the todolist to get the correct number *"
(ColorCode "black" "light grey") + "* - list numbering starts at 0 *"
(ColorCode "black" "light grey") + "* - Example: insert Deploy_Code 3 *"
(ColorCode "black" "light grey") + "* *"
(ColorCode "black" "grey") + "* info 1 *"
(ColorCode "black" "light grey") + "* - get the info for this task *"
(ColorCode "black" "light grey") + "* *"
(ColorCode "black" "grey") + "* take 1 *"
(ColorCode "black" "light grey") + "* - take a task. by taking this task you must to do it *"
(ColorCode "black" "light grey") + "* - if you don't complete it...we know where you live *"
(ColorCode "black" "light grey") + "* *"
(ColorCode "black" "grey") + "* done 1 *"
(ColorCode "black" "light grey") + "* - this is how you finish a task *"
(ColorCode "black" "light grey") + "* - you can only finish a task you've taken *"
(ColorCode "black" "light grey") + "* *"
(ColorCode "black" "grey") + "* fail 1 *"
(ColorCode "black" "light grey") + "* - this is how you fail a task *"
(ColorCode "black" "light grey") + "* *"
(ColorCode "black" "light grey") + "*********************************************************"
}
$query = [string]$args[0];
$param = $args[1];
$query = $query.split(" ");
switch($query[0])
{
"add" { Add-Todo $query[1] }
"insert" { Insert-Todo $query[1] $query[2]}
"take" { Take-Todo $query[1] $param.Nick}
"done" { Mark-Todo $query[1] $param.Nick}
"info" { Info-Todo $query[1]}
"fail" { Fail-Todo $query[1] $param.Nick}
"help" { Help-Todo }
default {Print-Todo}
}
#Write-Host "Ending Todo"