Get IRC Command response - command

I want to run an IRC Command, and get the response for it for bots.
Is there any way to do this?
for example, I want to get the result of "NAMES #channel" or "WHO #channel u"

You have to wait for 353 and 366 replies (for NAMES), and 354 and 315 for WHO.
For instance, when using NAMES:
(outgoing) NAMES #channel
(incoming) :wilhelm.freenode.net 353 botnick = #channel :user1 user2 user3 #user4
(incoming) :wilhelm.freenode.net 366 botnick #channel :End of /NAMES list.
And similarily when using WHO:
(outgoing) WHO #channel
(incoming) :wilhelm.freenode.net 354 botnick #channel ident host sendak.freenode.net nick H 0 nick :realname
[…]
(incoming) :wilhelm.freenode.net 315 botnick #channel :End of /WHO list.

Related

PowerShell - How to get the Tags and Comments property of a file [duplicate]

I want to edit the "Comments" Field of a file.
I see several examples how to read the files metadata, but am not seeing how to edit the files metadata?
Judging by this forum thread, you can only read such extended document properties via the Windows (GUI) shell (the Shell.Application COM API) - see next section.
For updating (editing) properties via .NET / PowerShell:
Unofficial 3rd-party NuGet packages that are .NET wrappers around Windows APIs may offer a solution, as demonstrated in this C# answer. Note that many variations of these packages (Microsoft.WindowsAPICodePack.*) exist in the NuGet gallery, with many forks of earlier, seemingly abandoned packages. An example of a fork that still appears to be maintained is this repo.
For image files, specifically, a standard .NET API does exist, although updating properties requires workarounds: see System.Drawing.Image.GetPropertyItem
Otherwise, you must use an application-specific API, such as the various COM libraries for Microsoft Office applications; e.g., New-Object -ComObject Word.Application; this documentation may provide further information.
Note that interactively, modifying - but not adding - properties via the Properties dialog in File Explorer may be possible, if a File Explorer extension is installed for a given document type (such as for Microsoft Word *.docx files).
Reading document properties programmatically:
$file = 'C:\path\to\some\file.doc'
# The index of the property to retrieve.
$propIndex = 24 # Comments
$folder = (New-Object -ComObject Shell.Application).NameSpace((Split-Path $file))
# Output the value of the "Comments" property.
$folder.GetDetailsOf(
$folder.ParseName((Split-Path -Leaf $file)),
24
)
Note that all property values are returned as strings, and that if the targeted property is not filled in, the empty string ('') is returned ; try 0 (the file's name) as a standard property to verify that the call works in principle.
Here's code that finds the indices of all supported property names:
$folder = (New-Object -ComObject Shell.Application).NameSpace("$pwd")
# Note: Assumes that no indices higher than 1000 exist.
0..1000 | % {
if ($n = $folder.GetDetailsOf($null, $_)) {
[pscustomobject] #{ Index = $_; Name = $n }
}
}
On my Windows 10 machine this yields:
Index Name
----- ----
0 Name
1 Size
2 Item type
3 Date modified
4 Date created
5 Date accessed
6 Attributes
7 Offline status
8 Availability
9 Perceived type
10 Owner
11 Kind
12 Date taken
13 Contributing artists
14 Album
15 Year
16 Genre
17 Conductors
18 Tags
19 Rating
20 Authors
21 Title
22 Subject
23 Categories
24 Comments
25 Copyright
26 #
27 Length
28 Bit rate
29 Protected
30 Camera model
31 Dimensions
32 Camera maker
33 Company
34 File description
35 Masters keywords
36 Masters keywords
42 Program name
43 Duration
44 Is online
45 Is recurring
46 Location
47 Optional attendee addresses
48 Optional attendees
49 Organizer address
50 Organizer name
51 Reminder time
52 Required attendee addresses
53 Required attendees
54 Resources
55 Meeting status
56 Free/busy status
57 Total size
58 Account name
60 Task status
61 Computer
62 Anniversary
63 Assistant's name
64 Assistant's phone
65 Birthday
66 Business address
67 Business city
68 Business country/region
69 Business P.O. box
70 Business postal code
71 Business state or province
72 Business street
73 Business fax
74 Business home page
75 Business phone
76 Callback number
77 Car phone
78 Children
79 Company main phone
80 Department
81 E-mail address
82 E-mail2
83 E-mail3
84 E-mail list
85 E-mail display name
86 File as
87 First name
88 Full name
89 Gender
90 Given name
91 Hobbies
92 Home address
93 Home city
94 Home country/region
95 Home P.O. box
96 Home postal code
97 Home state or province
98 Home street
99 Home fax
100 Home phone
101 IM addresses
102 Initials
103 Job title
104 Label
105 Last name
106 Mailing address
107 Middle name
108 Cell phone
109 Nickname
110 Office location
111 Other address
112 Other city
113 Other country/region
114 Other P.O. box
115 Other postal code
116 Other state or province
117 Other street
118 Pager
119 Personal title
120 City
121 Country/region
122 P.O. box
123 Postal code
124 State or province
125 Street
126 Primary e-mail
127 Primary phone
128 Profession
129 Spouse/Partner
130 Suffix
131 TTY/TTD phone
132 Telex
133 Webpage
134 Content status
135 Content type
136 Date acquired
137 Date archived
138 Date completed
139 Device category
140 Connected
141 Discovery method
142 Friendly name
143 Local computer
144 Manufacturer
145 Model
146 Paired
147 Classification
148 Status
149 Status
150 Client ID
151 Contributors
152 Content created
153 Last printed
154 Date last saved
155 Division
156 Document ID
157 Pages
158 Slides
159 Total editing time
160 Word count
161 Due date
162 End date
163 File count
164 File extension
165 Filename
166 File version
167 Flag color
168 Flag status
169 Space free
172 Group
173 Sharing type
174 Bit depth
175 Horizontal resolution
176 Width
177 Vertical resolution
178 Height
179 Importance
180 Is attachment
181 Is deleted
182 Encryption status
183 Has flag
184 Is completed
185 Incomplete
186 Read status
187 Shared
188 Creators
189 Date
190 Folder name
191 Folder path
192 Folder
193 Participants
194 Path
195 By location
196 Type
197 Contact names
198 Entry type
199 Language
200 Date visited
201 Description
202 Link status
203 Link target
204 URL
208 Media created
209 Date released
210 Encoded by
211 Episode number
212 Producers
213 Publisher
214 Season number
215 Subtitle
216 User web URL
217 Writers
219 Attachments
220 Bcc addresses
221 Bcc
222 Cc addresses
223 Cc
224 Conversation ID
225 Date received
226 Date sent
227 From addresses
228 From
229 Has attachments
230 Sender address
231 Sender name
232 Store
233 To addresses
234 To do title
235 To
236 Mileage
237 Album artist
238 Sort album artist
239 Album ID
240 Sort album
241 Sort contributing artists
242 Beats-per-minute
243 Composers
244 Sort composer
245 Disc
246 Initial key
247 Part of a compilation
248 Mood
249 Part of set
250 Period
251 Color
252 Parental rating
253 Parental rating reason
254 Space used
255 EXIF version
256 Event
257 Exposure bias
258 Exposure program
259 Exposure time
260 F-stop
261 Flash mode
262 Focal length
263 35mm focal length
264 ISO speed
265 Lens maker
266 Lens model
267 Light source
268 Max aperture
269 Metering mode
270 Orientation
271 People
272 Program mode
273 Saturation
274 Subject distance
275 White balance
276 Priority
277 Project
278 Channel number
279 Episode name
280 Closed captioning
281 Rerun
282 SAP
283 Broadcast date
284 Program description
285 Recording time
286 Station call sign
287 Station name
288 Summary
289 Snippets
290 Auto summary
291 Relevance
292 File ownership
293 Sensitivity
294 Shared with
295 Sharing status
297 Product name
298 Product version
299 Support link
300 Source
301 Start date
302 Sharing
303 Availability status
304 Status
305 Billing information
306 Complete
307 Task owner
308 Sort title
309 Total file size
310 Legal trademarks
311 Video compression
312 Directors
313 Data rate
314 Frame height
315 Frame rate
316 Frame width
317 Spherical
318 Stereo
319 Video orientation
320 Total bitrate
off the top of my head, I think you might be able to do it with by playing with the COM object
$myFileObj = Get-Item -Path "C:\path\to\file"
$shellCom = New-Object -ComObject Shell.Application
$sDirectory = $shellCom.NameSpace($myFileObj.Directory.FullName)
$sFile = $sDirectory.ParseName($myFileObj.Name)
Now do a Get-Member on the $sFile object, so $sFile | Get-Member. If you see that the property Comments has a setter, you should be able to change it. It'll have {get} {set} under Definition. Setting it should be as easy as $sFile.Comments = "blah blah blah"

Use PowerShell to edit a file's metadata (Details tab of a file in Windows file explorer)

I want to edit the "Comments" Field of a file.
I see several examples how to read the files metadata, but am not seeing how to edit the files metadata?
Judging by this forum thread, you can only read such extended document properties via the Windows (GUI) shell (the Shell.Application COM API) - see next section.
For updating (editing) properties via .NET / PowerShell:
Unofficial 3rd-party NuGet packages that are .NET wrappers around Windows APIs may offer a solution, as demonstrated in this C# answer. Note that many variations of these packages (Microsoft.WindowsAPICodePack.*) exist in the NuGet gallery, with many forks of earlier, seemingly abandoned packages. An example of a fork that still appears to be maintained is this repo.
For image files, specifically, a standard .NET API does exist, although updating properties requires workarounds: see System.Drawing.Image.GetPropertyItem
Otherwise, you must use an application-specific API, such as the various COM libraries for Microsoft Office applications; e.g., New-Object -ComObject Word.Application; this documentation may provide further information.
Note that interactively, modifying - but not adding - properties via the Properties dialog in File Explorer may be possible, if a File Explorer extension is installed for a given document type (such as for Microsoft Word *.docx files).
Reading document properties programmatically:
$file = 'C:\path\to\some\file.doc'
# The index of the property to retrieve.
$propIndex = 24 # Comments
$folder = (New-Object -ComObject Shell.Application).NameSpace((Split-Path $file))
# Output the value of the "Comments" property.
$folder.GetDetailsOf(
$folder.ParseName((Split-Path -Leaf $file)),
24
)
Note that all property values are returned as strings, and that if the targeted property is not filled in, the empty string ('') is returned ; try 0 (the file's name) as a standard property to verify that the call works in principle.
Here's code that finds the indices of all supported property names:
$folder = (New-Object -ComObject Shell.Application).NameSpace("$pwd")
# Note: Assumes that no indices higher than 1000 exist.
0..1000 | % {
if ($n = $folder.GetDetailsOf($null, $_)) {
[pscustomobject] #{ Index = $_; Name = $n }
}
}
On my Windows 10 machine this yields:
Index Name
----- ----
0 Name
1 Size
2 Item type
3 Date modified
4 Date created
5 Date accessed
6 Attributes
7 Offline status
8 Availability
9 Perceived type
10 Owner
11 Kind
12 Date taken
13 Contributing artists
14 Album
15 Year
16 Genre
17 Conductors
18 Tags
19 Rating
20 Authors
21 Title
22 Subject
23 Categories
24 Comments
25 Copyright
26 #
27 Length
28 Bit rate
29 Protected
30 Camera model
31 Dimensions
32 Camera maker
33 Company
34 File description
35 Masters keywords
36 Masters keywords
42 Program name
43 Duration
44 Is online
45 Is recurring
46 Location
47 Optional attendee addresses
48 Optional attendees
49 Organizer address
50 Organizer name
51 Reminder time
52 Required attendee addresses
53 Required attendees
54 Resources
55 Meeting status
56 Free/busy status
57 Total size
58 Account name
60 Task status
61 Computer
62 Anniversary
63 Assistant's name
64 Assistant's phone
65 Birthday
66 Business address
67 Business city
68 Business country/region
69 Business P.O. box
70 Business postal code
71 Business state or province
72 Business street
73 Business fax
74 Business home page
75 Business phone
76 Callback number
77 Car phone
78 Children
79 Company main phone
80 Department
81 E-mail address
82 E-mail2
83 E-mail3
84 E-mail list
85 E-mail display name
86 File as
87 First name
88 Full name
89 Gender
90 Given name
91 Hobbies
92 Home address
93 Home city
94 Home country/region
95 Home P.O. box
96 Home postal code
97 Home state or province
98 Home street
99 Home fax
100 Home phone
101 IM addresses
102 Initials
103 Job title
104 Label
105 Last name
106 Mailing address
107 Middle name
108 Cell phone
109 Nickname
110 Office location
111 Other address
112 Other city
113 Other country/region
114 Other P.O. box
115 Other postal code
116 Other state or province
117 Other street
118 Pager
119 Personal title
120 City
121 Country/region
122 P.O. box
123 Postal code
124 State or province
125 Street
126 Primary e-mail
127 Primary phone
128 Profession
129 Spouse/Partner
130 Suffix
131 TTY/TTD phone
132 Telex
133 Webpage
134 Content status
135 Content type
136 Date acquired
137 Date archived
138 Date completed
139 Device category
140 Connected
141 Discovery method
142 Friendly name
143 Local computer
144 Manufacturer
145 Model
146 Paired
147 Classification
148 Status
149 Status
150 Client ID
151 Contributors
152 Content created
153 Last printed
154 Date last saved
155 Division
156 Document ID
157 Pages
158 Slides
159 Total editing time
160 Word count
161 Due date
162 End date
163 File count
164 File extension
165 Filename
166 File version
167 Flag color
168 Flag status
169 Space free
172 Group
173 Sharing type
174 Bit depth
175 Horizontal resolution
176 Width
177 Vertical resolution
178 Height
179 Importance
180 Is attachment
181 Is deleted
182 Encryption status
183 Has flag
184 Is completed
185 Incomplete
186 Read status
187 Shared
188 Creators
189 Date
190 Folder name
191 Folder path
192 Folder
193 Participants
194 Path
195 By location
196 Type
197 Contact names
198 Entry type
199 Language
200 Date visited
201 Description
202 Link status
203 Link target
204 URL
208 Media created
209 Date released
210 Encoded by
211 Episode number
212 Producers
213 Publisher
214 Season number
215 Subtitle
216 User web URL
217 Writers
219 Attachments
220 Bcc addresses
221 Bcc
222 Cc addresses
223 Cc
224 Conversation ID
225 Date received
226 Date sent
227 From addresses
228 From
229 Has attachments
230 Sender address
231 Sender name
232 Store
233 To addresses
234 To do title
235 To
236 Mileage
237 Album artist
238 Sort album artist
239 Album ID
240 Sort album
241 Sort contributing artists
242 Beats-per-minute
243 Composers
244 Sort composer
245 Disc
246 Initial key
247 Part of a compilation
248 Mood
249 Part of set
250 Period
251 Color
252 Parental rating
253 Parental rating reason
254 Space used
255 EXIF version
256 Event
257 Exposure bias
258 Exposure program
259 Exposure time
260 F-stop
261 Flash mode
262 Focal length
263 35mm focal length
264 ISO speed
265 Lens maker
266 Lens model
267 Light source
268 Max aperture
269 Metering mode
270 Orientation
271 People
272 Program mode
273 Saturation
274 Subject distance
275 White balance
276 Priority
277 Project
278 Channel number
279 Episode name
280 Closed captioning
281 Rerun
282 SAP
283 Broadcast date
284 Program description
285 Recording time
286 Station call sign
287 Station name
288 Summary
289 Snippets
290 Auto summary
291 Relevance
292 File ownership
293 Sensitivity
294 Shared with
295 Sharing status
297 Product name
298 Product version
299 Support link
300 Source
301 Start date
302 Sharing
303 Availability status
304 Status
305 Billing information
306 Complete
307 Task owner
308 Sort title
309 Total file size
310 Legal trademarks
311 Video compression
312 Directors
313 Data rate
314 Frame height
315 Frame rate
316 Frame width
317 Spherical
318 Stereo
319 Video orientation
320 Total bitrate
off the top of my head, I think you might be able to do it with by playing with the COM object
$myFileObj = Get-Item -Path "C:\path\to\file"
$shellCom = New-Object -ComObject Shell.Application
$sDirectory = $shellCom.NameSpace($myFileObj.Directory.FullName)
$sFile = $sDirectory.ParseName($myFileObj.Name)
Now do a Get-Member on the $sFile object, so $sFile | Get-Member. If you see that the property Comments has a setter, you should be able to change it. It'll have {get} {set} under Definition. Setting it should be as easy as $sFile.Comments = "blah blah blah"

deleting unnecessary characters from txt document

I am facing a bit of a problem, i am not good at programming yet.
i have a text that looks like this:
D28151373 15-04 040 028230457 01-01 015 D28250305 01-08 048 D28250661 03-01 032 028151376 12-01 057 028230460 01-01 001 D28250305 01-09 049 D28250663 03-01 025 028151377 12-01 057 028230462 01-01 014
just like a million times longer.
What I need to do is to delete the first character and then keep the next 11 characters (including spaces) and the delete the next 9 characters, keep 11 characters, delete 9 characters, and on and on and on...
There must be a simple way to make a script do this automaticity but I simply can't figure out how. (BTW I am good at understanding the code but I am lost when i have to start myself) and what is the best program to do this simple task in, I was thinking about Notepad++ or C++.
Ctrl+H
Find what: .(.{11}).{8}
Replace with: $1 <-- there is a space after $1
Replace all
Explanation:
. : 1 character
(.{11}) : group 1, 11 characters
.{8} : 8 characters
Replacement:
$1 : group 1 and a space
Result for given example:
28151373 15 28230457 01 28250305 01 28250661 03 28151376 12 28230460 01 28250305 01 28250663 03 28151377 12 28230462 01
You may also use a Notepad++ macro:
Macro → Start Recording
Del Ctrl+→ → → Del Del Del Del Del Del Del →
Macro → Stop Recording
Macro → Run a Macro Multiple Times...

Filter textual data and count records corresponding to a specific value [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
From the data below I would like to find out how many unique "Over quota" lines there are corresponding to the ID values that start each line (e.g. 38148141CEB*), Each ID should only be counted once, even though there are multiple "Over quota" lines. What sort of data structure would be best to use for this task? How can I transform the data to achieve this?
Sample Input
38148141CEB* 55166 Tue May 19 20:38:45 aaa#bbb.com
aaa#nwegweg.com
AABFF141D0F* 6289 Tue May 19 20:38:44 MAILER-DAEMON
rgerg#rgerger.com
3F384141CAF* 15422 Tue May 19 20:38:44 MAILER-DAEMON
gregrg#gserhweh.com
6E5F1142129 59842 Tue May 19 17:22:39 rhgregr#grehedh.in
(connect to mail.rtherh.com.hk[118.142.113.41]:25: Connection timed out)
hbed#herer.com.hk
64ACF141E4D 7026 Tue May 19 14:21:14 hdtjndtrj#tjrftjnrf.com
(host hergherhe.herherh.com[172.16.12.160] said: 452 4.2.2 Over quota (in reply to end of DATA command))
c#rhedhed.com
(host hergherhe.herherh.com[172.16.12.160] said: 452 4.2.2 Over quota (in reply to end of DATA command))
c#rhedhed.com
67E1A1420CF 2993 Tue May 19 12:36:45 erhejhe
(host z.rherh.com[172.16.12.164] said: 452 4.2.2 Over quota (in reply to end of DATA command))
heehedh88#drehnjedthnj.com
(host hergherhe.herherh.com[172.16.12.160] said: 452 4.2.2 Over quota (in reply to end of DATA command))
c#rhedhed.com
680911418C9 11041 Tue May 19 13:59:49 efswegrwe
(host zgewsegws.nrhsrhedr.com[172.16.12.161] said: 452 4.2.2 Over quota (in reply to end of DATA command))
wrhwrg#etheherg.com
666611416DD 29459 Tue May 19 11:35:58 erherhe#ejerthjrth.com
(host herer.herwsrh.com[172.16.12.152] said: 452 4.2.2 Over quota (in reply to end of DATA command))
rggerhed#erhjehjedtr.com
(host hergherhe.herherh.com[172.16.12.160] said: 452 4.2.2 Over quota (in reply to end of DATA command))
c#rhedhed.com
(host hergherhe.herherh.com[172.16.12.160] said: 452 4.2.2 Over quota (in reply to end of DATA command))
c#rhedhed.com
643F9142006 11077 Tue May 19 11:34:32 tejeastj#eherjhe.com
(Host or domain name not found. Name service error for name=tjedtjedt.com type=MX: Host not found, try again)
tedjedth#edtjedthghr.com
62980141A8C 464040 Tue May 19 15:52:06 etjertj#jrtjedtj.com.hk
(host zherherh.com[172.16.12.159] said: 452 4.2.2 Over quota (in reply to end of DATA command))
trjerjer#rherherh.com
6DD47142017 20049 Tue May 19 11:04:34 erhedrhje
(host ejedtjedrth.com[172.16.12.161] said: 452 4.2.2 Over quota (in reply to end of DATA command))
ehjdthjdr#etjtdfteh.com
696AD1420A4 7679 Tue May 19 15:09:05 wrgwsrg
(host rwherhe.hre.com[172.16.12.157] said: 452 4.2.2 Over quota (in reply to end of DATA command))
wegw#gwrhbwrg.com
Sample output
The output I need would look something like this:
7 Over quota:
64ACF141E4D, 67E1A1420CF, 680911418C9, 666611416DD, 62980141A8C, 6DD47142017, 696AD1420A4
You can transform your data into an array of arrays and then iterate through the array elements to check for the "Over quota" statement.
This one-liner will split the input on blank lines (split/\n{2,}/) and uses push to put the resulting records in an array (#quotalog) of anonymous arrays (note the anonymous array constructors [ ]):
perl -n0E 'push #quotalog, map { s/\s+/ /gr ; [split] } split/\n{2,}/ ;
for (#quotalog){ say $_->[0] if ("#$_" =~ /Over/) }' quotadata.txt
Output:
64ACF141E4D
67E1A1420CF
680911418C9
666611416DD
62980141A8C
6DD47142017
696AD1420A4
Or, to approximate your sample output:
perl -n0E 'push #quotalog, map { [split] } split/\n{2,}/ ;
for (#quotalog){ push #over, $_->[0] if ("#$_" =~ /Over/) }
print ~~#over, " Over quota:\n" ; print join ", ", #over,"\n";' quotadata.txt
Output:
7 Over quota:
64ACF141E4D, 67E1A1420CF, 680911418C9, 666611416DD, 62980141A8C, 6DD47142017, 696AD1420A4,
You might instead want to transform the data into a hash of arrays. Here we use a "double map to a hash" to create the hash and Data::Dumper to view it (as an alternative you could use Data::Printer):
perl -MData::Dumper -n0E 'map { $quotas{$_->[0]} = [ #{ $_ }[1...$#$_] ] }
map { [ split ] } split/\n{2,}/ ; print Dumper \%quotas' quotadata.txt
This is just for illustrative purposes - the second map (i.e. the first map the list of split records sees) might be better using a regex instead of a simple split. In any case, once your data is nicely arranged your can begin to extract information from it - though for that a longer script form application would be more appropriate.
Have a terminal or browser window open on The Perl Data Structures Cookbook (cf. perdoc perldsc) as you experiment and you'll learn quite a bit with your relatively simple exercise.

Perl print $(^b)

When I found Perl's $^O, I was curious whether there are more variables like this, because ^ reminded me of a regular expression. When I enter
print "$(^b)";
it comes up with some numbers:
1000 81 90 91 92 93 100 150 1000
What to these mean? Is this some kind of 0xdeadbeef?
I think you are just printing out the value of $(.
The real gid of this process. If you are on a machine that supports membership in multiple groups simultaneously, gives a space separated list of groups you are in. The first number is the one returned by getgid() , and the subsequent ones by getgroups() , one of which may be the same as the first number.
However, a value assigned to $( must be a single number used to set the real gid. So the value given by $( should not be assigned back to $( without being forced numeric, such as by adding zero. Note that this is different to the effective gid ($) ) which does take a list.
You can change both the real gid and the effective gid at the same time by using POSIX::setgid() . Changes to $( require a check to $! to detect any possible errors after an attempted change.
Here is the comparison:
diff <(perl -le 'print "$(";') <(perl -le 'print "$(^b)";')
1c1
< 20 20 402 12 33 61 79 80 81 98 100 204 401
---
> 20 20 402 12 33 61 79 80 81 98 100 204 401^b)
See the documentation on perldoc perlvar for a list of all the various built-in variables (along with their use English; equivalent names).