Ver código fonte

help: Generate index of help topics

tags/v0.8.0
Daniel Oaks 7 anos atrás
pai
commit
51425b7764
4 arquivos alterados com 109 adições e 12 exclusões
  1. 4
    0
      irc/commands.go
  2. 101
    11
      irc/help.go
  3. 1
    1
      irc/nickserv.go
  4. 3
    0
      irc/server.go

+ 4
- 0
irc/commands.go Ver arquivo

95
 		handler:   helpHandler,
95
 		handler:   helpHandler,
96
 		minParams: 0,
96
 		minParams: 0,
97
 	},
97
 	},
98
+	"HELPOP": {
99
+		handler:   helpHandler,
100
+		minParams: 0,
101
+	},
98
 	"INVITE": {
102
 	"INVITE": {
99
 		handler:   inviteHandler,
103
 		handler:   inviteHandler,
100
 		minParams: 2,
104
 		minParams: 2,

+ 101
- 11
irc/help.go Ver arquivo

4
 package irc
4
 package irc
5
 
5
 
6
 import (
6
 import (
7
+	"fmt"
8
+	"sort"
7
 	"strings"
9
 	"strings"
8
 
10
 
9
 	"github.com/DanielOaks/girc-go/ircmsg"
11
 	"github.com/DanielOaks/girc-go/ircmsg"
10
 )
12
 )
11
 
13
 
14
+// HelpEntryType represents the different sorts of help entries that can exist.
15
+type HelpEntryType int
16
+
17
+const (
18
+	CommandHelpEntry     HelpEntryType = 0
19
+	InformationHelpEntry HelpEntryType = 1
20
+	ISupportHelpEntry    HelpEntryType = 2
21
+)
22
+
12
 // HelpEntry represents an entry in the Help map.
23
 // HelpEntry represents an entry in the Help map.
13
 type HelpEntry struct {
24
 type HelpEntry struct {
14
-	oper bool
15
-	text string
25
+	oper      bool
26
+	text      string
27
+	helpType  HelpEntryType
28
+	duplicate bool
16
 }
29
 }
17
 
30
 
18
 // used for duplicates
31
 // used for duplicates
128
 	"help": {
141
 	"help": {
129
 		text: `HELP <argument>
142
 		text: `HELP <argument>
130
 
143
 
131
-Get an explanation of <argument>.`,
144
+Get an explanation of <argument>, or "index" for a list of help topics.`,
145
+	},
146
+	"helpop": {
147
+		text: `HELPOP <argument>
148
+
149
+Get an explanation of <argument>, or "index" for a list of help topics.`,
132
 	},
150
 	},
133
 	"invite": {
151
 	"invite": {
134
 		text: `INVITE <nickname> <channel>
152
 		text: `INVITE <nickname> <channel>
411
 
429
 
412
 	// Informational
430
 	// Informational
413
 	"modes": {
431
 	"modes": {
414
-		text: cmodeHelpText + "\n\n" + umodeHelpText,
432
+		text:     cmodeHelpText + "\n\n" + umodeHelpText,
433
+		helpType: InformationHelpEntry,
415
 	},
434
 	},
416
 	"cmode": {
435
 	"cmode": {
417
-		text: cmodeHelpText,
436
+		text:     cmodeHelpText,
437
+		helpType: InformationHelpEntry,
418
 	},
438
 	},
419
 	"cmodes": {
439
 	"cmodes": {
420
-		text: cmodeHelpText,
440
+		text:      cmodeHelpText,
441
+		helpType:  InformationHelpEntry,
442
+		duplicate: true,
421
 	},
443
 	},
422
 	"umode": {
444
 	"umode": {
423
-		text: umodeHelpText,
445
+		text:     umodeHelpText,
446
+		helpType: InformationHelpEntry,
424
 	},
447
 	},
425
 	"umodes": {
448
 	"umodes": {
426
-		text: umodeHelpText,
449
+		text:      umodeHelpText,
450
+		helpType:  InformationHelpEntry,
451
+		duplicate: true,
427
 	},
452
 	},
428
 
453
 
429
 	// RPL_ISUPPORT
454
 	// RPL_ISUPPORT
433
 Oragono supports an experimental unicode casemapping designed for extended
458
 Oragono supports an experimental unicode casemapping designed for extended
434
 Unicode support. This casemapping is based off RFC 7613 and the draft rfc7613
459
 Unicode support. This casemapping is based off RFC 7613 and the draft rfc7613
435
 casemapping spec here: http://oragono.io/specs.html`,
460
 casemapping spec here: http://oragono.io/specs.html`,
461
+		helpType: ISupportHelpEntry,
436
 	},
462
 	},
437
 	"prefix": {
463
 	"prefix": {
438
 		text: `RPL_ISUPPORT PREFIX
464
 		text: `RPL_ISUPPORT PREFIX
444
   +o (@)  |  Operator channel mode.
470
   +o (@)  |  Operator channel mode.
445
   +h (%)  |  Halfop channel mode.
471
   +h (%)  |  Halfop channel mode.
446
   +v (+)  |  Voice channel mode.`,
472
   +v (+)  |  Voice channel mode.`,
473
+		helpType: ISupportHelpEntry,
447
 	},
474
 	},
448
 }
475
 }
449
 
476
 
477
+// HelpIndex contains the list of all help topics for regular users.
478
+var HelpIndex = "list of all help topics for regular users"
479
+
480
+// HelpIndexOpers contains the list of all help topics for opers.
481
+var HelpIndexOpers = "list of all help topics for opers"
482
+
483
+// GenerateHelpIndex is used to generate HelpIndex.
484
+func GenerateHelpIndex(forOpers bool) string {
485
+	newHelpIndex := `= Help Topics =
486
+
487
+Commands:
488
+%s
489
+
490
+RPL_ISUPPORT Tokens:
491
+%s
492
+
493
+Information:
494
+%s`
495
+
496
+	// generate them
497
+	var commands, isupport, information []string
498
+
499
+	var line string
500
+	for name, info := range Help {
501
+		if info.duplicate {
502
+			continue
503
+		}
504
+		if info.oper && !forOpers {
505
+			continue
506
+		}
507
+
508
+		line = fmt.Sprintf("   %s", name)
509
+
510
+		if info.helpType == CommandHelpEntry {
511
+			commands = append(commands, line)
512
+		} else if info.helpType == ISupportHelpEntry {
513
+			isupport = append(isupport, line)
514
+		} else if info.helpType == InformationHelpEntry {
515
+			information = append(information, line)
516
+		}
517
+	}
518
+
519
+	// sort the lines
520
+	sort.Strings(commands)
521
+	sort.Strings(isupport)
522
+	sort.Strings(information)
523
+
524
+	// sub them in
525
+	newHelpIndex = fmt.Sprintf(newHelpIndex, strings.Join(commands, "\n"), strings.Join(isupport, "\n"), strings.Join(information, "\n"))
526
+
527
+	return newHelpIndex
528
+}
529
+
450
 // sendHelp sends the client help of the given string.
530
 // sendHelp sends the client help of the given string.
451
 func (client *Client) sendHelp(name string, text string) {
531
 func (client *Client) sendHelp(name string, text string) {
452
 	splitName := strings.Split(name, " ")
532
 	splitName := strings.Split(name, " ")
462
 		}
542
 		}
463
 	}
543
 	}
464
 	args := splitName
544
 	args := splitName
465
-	args = append(args, "End of /HELP")
545
+	args = append(args, "End of /HELPOP")
466
 	client.Send(nil, client.server.name, RPL_ENDOFHELP, args...)
546
 	client.Send(nil, client.server.name, RPL_ENDOFHELP, args...)
467
 }
547
 }
468
 
548
 
471
 	argument := strings.ToLower(strings.TrimSpace(strings.Join(msg.Params, " ")))
551
 	argument := strings.ToLower(strings.TrimSpace(strings.Join(msg.Params, " ")))
472
 
552
 
473
 	if len(argument) < 1 {
553
 	if len(argument) < 1 {
474
-		client.sendHelp("HELP", `HELP <argument>
554
+		client.sendHelp("HELPOP", `HELPOP <argument>
475
 
555
 
476
-Get an explanation of <argument>.`)
556
+Get an explanation of <argument>, or "index" for a list of help topics.`)
557
+		return false
558
+	}
559
+
560
+	// handle index
561
+	if argument == "index" {
562
+		if client.flags[Operator] {
563
+			client.sendHelp("HELP", HelpIndexOpers)
564
+		} else {
565
+			client.sendHelp("HELP", HelpIndex)
566
+		}
477
 		return false
567
 		return false
478
 	}
568
 	}
479
 
569
 

+ 1
- 1
irc/nickserv.go Ver arquivo

20
 }
20
 }
21
 
21
 
22
 func (server *Server) nickservReceivePrivmsg(client *Client, message string) {
22
 func (server *Server) nickservReceivePrivmsg(client *Client, message string) {
23
-	client.Notice("NickServ is not yet implemented, sorry! To register an account, check /HELP REG")
23
+	client.Notice("NickServ is not yet implemented, sorry! To register an account, check /HELPOP REG")
24
 }
24
 }

+ 3
- 0
irc/server.go Ver arquivo

156
 			return nil, fmt.Errorf("Help entry does not exist for command %s", name)
156
 			return nil, fmt.Errorf("Help entry does not exist for command %s", name)
157
 		}
157
 		}
158
 	}
158
 	}
159
+	// generate help indexes
160
+	HelpIndex = GenerateHelpIndex(false)
161
+	HelpIndexOpers = GenerateHelpIndex(true)
159
 
162
 
160
 	if config.Accounts.AuthenticationEnabled {
163
 	if config.Accounts.AuthenticationEnabled {
161
 		SupportedCapabilities[SASL] = true
164
 		SupportedCapabilities[SASL] = true

Carregando…
Cancelar
Salvar