@@ -255,30 +255,30 @@ pub async fn edit_embed(
255255 Ok ( ( ) )
256256}
257257
258- /// Adds an issue token
259- #[ poise:: command( rename = "add-issue-token " , slash_command, guild_only) ]
260- pub async fn add_issue_token (
258+ /// Adds a repository token
259+ #[ poise:: command( rename = "add-repository " , slash_command, guild_only) ]
260+ pub async fn add_repo (
261261 ctx : Context < ' _ > ,
262- #[ description = "The key to the issue token in a lowercase alphabetic string" ] key : String ,
262+ #[ description = "The key to the repository in a lowercase alphabetic string" ] key : String ,
263263 #[ description = "The owner of the repository." ] owner : String ,
264264 #[ description = "The respository name." ] repository : String ,
265265) -> Result < ( ) , Error > {
266266 let key_regex = Regex :: new ( r"[a-z+]+$" ) . unwrap ( ) ;
267- let repo_details_regex = Regex :: new ( r"^[a-zA-Z0-9](?: [a-zA-Z0-9.-]*[a-zA-Z0-9])? $" ) . unwrap ( ) ;
267+ let repo_details_regex = Regex :: new ( r"^( [a-zA-Z0-9-_]+)* $" ) . unwrap ( ) ;
268268 if !key_regex. is_match ( & key) {
269269 respond_err (
270270 & ctx,
271- "Issue token parsing error" ,
272- "The key is limited to lowercase letters only ." ,
271+ "Key parsing error" ,
272+ "The key can only lowercase ASCII letters, digits, and the characters ., -, and _ ." ,
273273 )
274274 . await ;
275275 return Ok ( ( ) ) ;
276276 }
277- if !repo_details_regex. is_match ( & key ) || !repo_details_regex. is_match ( & repository) {
277+ if !repo_details_regex. is_match ( & owner ) || !repo_details_regex. is_match ( & repository) {
278278 respond_err (
279279 & ctx,
280- "Issue token parsing error" ,
281- "Your inputs for owner and repository name must be valid." ,
280+ "Repository details parsing error" ,
281+ "Your inputs for owner and repository name must be valid repository names ." ,
282282 )
283283 . await ;
284284 return Ok ( ( ) ) ;
@@ -291,10 +291,14 @@ pub async fn add_issue_token(
291291 name : repository. clone ( ) ,
292292 } ;
293293
294- rwlock_guard. issue_prefixes . insert ( key. clone ( ) , details) ;
294+ rwlock_guard
295+ . issue_prefixes
296+ . insert ( key. clone ( ) . to_lowercase ( ) , details) ;
295297 println ! (
296- "Successfully added issue token {} for **{}/{}**" ,
297- key, owner, repository
298+ "Successfully added repository {} for **{}/{}**" ,
299+ key. to_lowercase( ) ,
300+ owner,
301+ repository
298302 ) ;
299303 rwlock_guard. write ( ) ;
300304 } ;
@@ -309,28 +313,28 @@ pub async fn add_issue_token(
309313 Ok ( ( ) )
310314}
311315
312- /// Removes an issue token.
313- #[ poise:: command( rename = "remove-issue-token " , slash_command, guild_only) ]
314- pub async fn remove_issue_token (
316+ /// Removes a repository
317+ #[ poise:: command( rename = "remove-repository " , slash_command, guild_only) ]
318+ pub async fn remove_repo (
315319 ctx : Context < ' _ > ,
316320 #[ autocomplete = "autocomplete_key" ]
317- #[ description = "The issue token key." ]
321+ #[ description = "The repository key." ]
318322 key : String ,
319323) -> Result < ( ) , Error > {
320324 // I know we could just do rm_repo, but that doesn't return a result.
321325 // I may change this in the future, but before I do that I'll probably
322326 // impl a solution directly into the types?
323327
324328 // not sure why I have to do this, it won't settle otherwise.
325- let key_str = format ! ( "The issue token with the key '{}' has been removed" , key) ;
329+ let key_str = format ! ( "The repository with the key '{}' has been removed" , key) ;
326330 match get_repo_details ( & ctx, & key) . await {
327331 Some ( _) => {
328332 rm_repo ( & ctx, & key) . await ;
329333
330- respond_ok ( & ctx, "Successfully removed token !" , & key_str) . await ;
334+ respond_ok ( & ctx, "Successfully removed repository !" , & key_str) . await ;
331335 }
332336 None => {
333- let title = "Failure to find issue token " ;
337+ let title = "Failure to find repository " ;
334338 let content = format ! ( "The key '{}' does not exist." , key) ;
335339 respond_err ( & ctx, title, & content) . await ;
336340 }
@@ -339,24 +343,51 @@ pub async fn remove_issue_token(
339343 Ok ( ( ) )
340344}
341345
342- /// Lists all snippets
346+ /// Lists all repositories
343347#[ poise:: command(
344- rename = "list-tokens" ,
348+ rename = "list-repositories" ,
349+ aliases( "repos-list" , "list-repos" , "repos" ) ,
345350 slash_command,
346351 prefix_command,
347352 guild_only,
348353 track_edits
349354) ]
350- pub async fn list_tokens ( ctx : Context < ' _ > ) -> Result < ( ) , Error > {
355+ pub async fn list_repos ( ctx : Context < ' _ > ) -> Result < ( ) , Error > {
351356 let tokens = { ctx. data ( ) . state . read ( ) . unwrap ( ) . issue_prefixes . clone ( ) } ;
352357
358+ if tokens. is_empty ( ) {
359+ respond_err (
360+ & ctx,
361+ "Cannot send list of repositories" ,
362+ "There are no repositories to list!" ,
363+ )
364+ . await ;
365+ return Ok ( ( ) ) ;
366+ }
367+
368+ let pages: Vec < Vec < ( String , String , bool ) > > = tokens
369+ . iter ( )
370+ . map ( |token| {
371+ (
372+ token. 0 . clone ( ) ,
373+ format ! ( "{}/{}" , token. 1 . name, token. 1 . owner) ,
374+ true ,
375+ )
376+ } )
377+ . collect :: < Vec < ( String , String , bool ) > > ( )
378+ . chunks ( 25 )
379+ . map ( |chunk| chunk. to_vec ( ) )
380+ . collect ( ) ;
381+
382+ super :: paginate_lists ( ctx, & pages, "Repositories" ) . await ?;
383+
353384 let mut embed = CreateEmbed :: default ( )
354385 . title ( "Issue tokens" )
355386 . color ( Colour :: TEAL ) ;
356387
357388 // fields are limited to 25 max, we can't display more than 25 snippets in the snippets command
358389 // due to a discord limitation.
359- for token in tokens. iter ( ) . take ( 25 ) {
390+ for token in tokens {
360391 embed = embed. field (
361392 format ! ( "**{}**" , token. 0 ) ,
362393 format ! ( "{}/{}" , token. 1 . owner, token. 1 . name) ,
0 commit comments