botrs 0.2.7

A Rust QQ Bot framework based on QQ Guild Bot API
Documentation
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
# Other Types API Reference

This module covers additional data structures and utility types used throughout the QQ Guild Bot API.

## Audio and Voice Types

### `Audio`

Represents audio controls and status in voice channels.

```rust
pub struct Audio {
    pub audio_control: Option<AudioControl>,
    pub audio_status: Option<AudioStatus>,
}
```

#### Fields

- `audio_control`: Control actions for audio playback
- `audio_status`: Current status of audio in the channel

### `AudioControl`

Audio control operations.

```rust
pub struct AudioControl {
    pub audio_url: Option<String>,
    pub text: Option<String>,
    pub status: Option<u32>,
}
```

#### Fields

- `audio_url`: URL of the audio file to play
- `text`: Text description of the audio
- `status`: Audio playback status (0: pause, 1: play)

### `AudioStatus`

Current audio playback status.

```rust
pub struct AudioStatus {
    pub start_time: Option<String>,
    pub end_time: Option<String>,
    pub status: Option<u32>,
}
```

#### Fields

- `start_time`: When audio playback started
- `end_time`: When audio playback ended
- `status`: Current playback status

### `PublicAudio`

Public audio channel information.

```rust
pub struct PublicAudio {
    pub audio_type: Option<PublicAudioType>,
    pub channel_id: Option<String>,
    pub guild_id: Option<String>,
    pub user_id: Option<String>,
}
```

#### Fields

- `audio_type`: Type of audio event (enter/exit)
- `channel_id`: ID of the audio channel
- `guild_id`: ID of the guild
- `user_id`: ID of the user involved

### `PublicAudioType`

Audio channel event types.

```rust
pub enum PublicAudioType {
    Enter = 1,
    Exit = 2,
}
```

#### Variants

- `Enter`: User entered an audio channel
- `Exit`: User left an audio channel

## Forum and Thread Types

### `Thread`

Represents a forum thread.

```rust
pub struct Thread {
    pub guild_id: String,
    pub channel_id: String,
    pub author_id: String,
    pub thread_info: ThreadInfo,
}
```

#### Fields

- `guild_id`: ID of the guild containing the thread
- `channel_id`: ID of the forum channel
- `author_id`: ID of the thread author
- `thread_info`: Detailed thread information

### `ThreadInfo`

Detailed information about a thread.

```rust
pub struct ThreadInfo {
    pub thread_id: String,
    pub title: String,
    pub content: String,
    pub date_time: String,
}
```

#### Fields

- `thread_id`: Unique thread identifier
- `title`: Thread title
- `content`: Thread content/description
- `date_time`: Thread creation timestamp

### `OpenThread`

Open forum thread with additional metadata.

```rust
pub struct OpenThread {
    pub guild_id: String,
    pub channel_id: String,
    pub author_id: String,
    pub thread_info: ThreadInfo,
    pub task_id: Option<String>,
    pub event_id: Option<String>,
}
```

#### Fields

- `guild_id`: Guild ID
- `channel_id`: Channel ID
- `author_id`: Author ID
- `thread_info`: Thread information
- `task_id`: Associated task ID
- `event_id`: Event ID for tracking

## Permission Types

### `Permission`

Represents permissions for channels and roles.

```rust
pub struct Permission {
    pub channel_id: String,
    pub user_id: Option<String>,
    pub role_id: Option<String>,
    pub permissions: String,
}
```

#### Fields

- `channel_id`: Channel these permissions apply to
- `user_id`: User ID (for user-specific permissions)
- `role_id`: Role ID (for role-based permissions)
- `permissions`: Permission bit flags as string

### `ChannelPermissions`

Channel-specific permission configuration.

```rust
pub struct ChannelPermissions {
    pub channel_id: String,
    pub permissions: String,
}
```

## Schedule Types

### `Schedule`

Represents a scheduled event or task.

```rust
pub struct Schedule {
    pub id: String,
    pub name: String,
    pub description: Option<String>,
    pub start_timestamp: String,
    pub end_timestamp: String,
    pub creator: Option<Member>,
    pub jump_channel_id: Option<String>,
    pub remind_type: String,
}
```

#### Fields

- `id`: Unique schedule identifier
- `name`: Schedule name/title
- `description`: Optional description
- `start_timestamp`: When the event starts
- `end_timestamp`: When the event ends
- `creator`: Member who created the schedule
- `jump_channel_id`: Channel to direct users to
- `remind_type`: Type of reminder notifications

## Interaction Types

### `Interaction`

Represents user interactions with bot components.

```rust
pub struct Interaction {
    pub id: String,
    pub application_id: String,
    pub interaction_type: InteractionType,
    pub data: Option<InteractionData>,
    pub guild_id: Option<String>,
    pub channel_id: Option<String>,
    pub user: Option<User>,
    pub member: Option<Member>,
    pub token: String,
    pub version: u32,
}
```

#### Fields

- `id`: Unique interaction identifier
- `application_id`: Bot application ID
- `interaction_type`: Type of interaction
- `data`: Interaction-specific data
- `guild_id`: Guild where interaction occurred
- `channel_id`: Channel where interaction occurred
- `user`: User who triggered the interaction
- `member`: Member information if in guild
- `token`: Interaction token for responses
- `version`: API version

### `InteractionType`

Types of user interactions.

```rust
pub enum InteractionType {
    Ping = 1,
    ApplicationCommand = 2,
    MessageComponent = 3,
}
```

#### Variants

- `Ping`: Ping interaction for verification
- `ApplicationCommand`: Slash command execution
- `MessageComponent`: Button or select menu interaction

### `InteractionData`

Data payload for interactions.

```rust
pub struct InteractionData {
    pub data_type: InteractionDataType,
    pub resolved: Option<serde_json::Value>,
}
```

#### Fields

- `data_type`: Type of interaction data
- `resolved`: Resolved entities (users, roles, channels, etc.)

## Reaction Types

### `Reaction`

Represents emoji reactions on messages.

```rust
pub struct Reaction {
    pub target: ReactionTarget,
    pub emoji_type: u32,
    pub emoji_id: String,
}
```

#### Fields

- `target`: What the reaction is applied to
- `emoji_type`: Type of emoji (1: system, 2: custom)
- `emoji_id`: Emoji identifier

### `ReactionTarget`

Target for emoji reactions.

```rust
pub struct ReactionTarget {
    pub target_type: ReactionTargetType,
    pub id: String,
}
```

#### Fields

- `target_type`: Type of target (message, etc.)
- `id`: Target identifier

### `ReactionTargetType`

Types of reaction targets.

```rust
pub enum ReactionTargetType {
    Message = 0,
}
```

### `ReactionUsers`

Users who reacted with a specific emoji.

```rust
pub struct ReactionUsers {
    pub users: Vec<User>,
    pub cookie: Option<String>,
    pub is_end: Option<bool>,
}
```

#### Fields

- `users`: List of users who reacted
- `cookie`: Pagination token
- `is_end`: Whether this is the last page

## Management Event Types

### `C2CManageEvent`

Client-to-client management events.

```rust
pub struct C2CManageEvent {
    pub event_type: ManageEventType,
    pub timestamp: u64,
    pub openid: String,
}
```

#### Fields

- `event_type`: Type of management event
- `timestamp`: Event timestamp
- `openid`: User's OpenID

### `GroupManageEvent`

Group management events.

```rust
pub struct GroupManageEvent {
    pub event_type: ManageEventType,
    pub timestamp: u64,
    pub group_openid: String,
    pub op_member_openid: String,
}
```

#### Fields

- `event_type`: Type of management event
- `timestamp`: Event timestamp
- `group_openid`: Group's OpenID
- `op_member_openid`: Operating member's OpenID

### `ManageEventType`

Types of management events.

```rust
pub enum ManageEventType {
    FriendAdd = 11001,
    FriendDel = 11002,
    C2cMsgReject = 11003,
    C2cMsgReceive = 11004,
    GroupAddRobot = 12001,
    GroupDelRobot = 12002,
    GroupMsgReject = 12003,
    GroupMsgReceive = 12004,
}
```

## Gateway Types

### `Ready`

Ready event data when bot connects.

```rust
pub struct Ready {
    pub version: u32,
    pub session_id: String,
    pub user: BotInfo,
    pub shard: Option<[u32; 2]>,
}
```

#### Fields

- `version`: Gateway version
- `session_id`: Session identifier for this connection
- `user`: Bot user information
- `shard`: Shard information [shard_id, shard_count]

### `ConnectionSession`

Session information for the gateway connection.

```rust
pub struct ConnectionSession {
    pub session_id: String,
    pub shard_id: u32,
    pub shard_count: u32,
    pub last_sequence: Option<u64>,
}
```

#### Fields

- `session_id`: Unique session identifier
- `shard_id`: Current shard ID (0-based)
- `shard_count`: Total number of shards
- `last_sequence`: Last received sequence number

### `ConnectionState`

Current state of the gateway connection.

```rust
pub enum ConnectionState {
    Disconnected,
    Connecting,
    Connected,
    Reconnecting,
    Closing,
}
```

#### Variants

- `Disconnected`: Not connected to gateway
- `Connecting`: Attempting to connect
- `Connected`: Successfully connected and ready
- `Reconnecting`: Attempting to reconnect after disconnect
- `Closing`: Gracefully closing connection

## Utility Types

### `HasId`

Trait for types that have an ID field.

```rust
pub trait HasId {
    fn id(&self) -> &str;
}
```

This trait is implemented by most entities (messages, users, guilds, etc.) to provide a consistent way to access their identifier.

### `Session`

Session management utilities.

```rust
pub struct Session {
    pub url: String,
    pub shards: u32,
    pub session_start_limit: SessionStartLimit,
}
```

### `SessionStartLimit`

Limits on session starts.

```rust
pub struct SessionStartLimit {
    pub total: u32,
    pub remaining: u32,
    pub reset_after: u64,
    pub max_concurrency: u32,
}
```

## Common Usage Patterns

### Audio Channel Management

```rust
async fn manage_audio_channel(ctx: Context, channel_id: &str) -> Result<()> {
    // Play audio in channel
    let audio_control = AudioControl {
        audio_url: Some("https://example.com/audio.mp3".to_string()),
        text: Some("Now playing background music".to_string()),
        status: Some(1), // Play
    };
    
    ctx.update_audio(channel_id, &audio_control).await?;
    println!("Started audio playback");
    
    // Wait and then stop
    tokio::time::sleep(std::time::Duration::from_secs(30)).await;
    
    let stop_control = AudioControl {
        audio_url: None,
        text: Some("Audio stopped".to_string()),
        status: Some(0), // Pause
    };
    
    ctx.update_audio(channel_id, &stop_control).await?;
    println!("Stopped audio playback");
    
    Ok(())
}
```

### Forum Thread Creation

```rust
async fn create_forum_thread(
    ctx: Context,
    channel_id: &str,
    title: &str,
    content: &str,
) -> Result<OpenThread> {
    use botrs::forum::{Title, Content, Format};
    
    let thread_title = Title {
        text: title.to_string(),
        paragraphs: vec![],
    };
    
    let thread_content = Content {
        paragraphs: vec![content.to_string()],
    };
    
    let thread = ctx.api.create_thread(
        &ctx.token,
        channel_id,
        &thread_title,
        &thread_content,
        &Format::Text,
    ).await?;
    
    println!("Created forum thread: {}", thread.thread_info.title);
    Ok(thread)
}
```

### Reaction Management

```rust
async fn manage_reactions(ctx: Context, channel_id: &str, message_id: &str) -> Result<()> {
    // Add reaction
    let reaction = Reaction {
        target: ReactionTarget {
            target_type: ReactionTargetType::Message,
            id: message_id.to_string(),
        },
        emoji_type: 1, // System emoji
        emoji_id: "128077".to_string(), // Thumbs up
    };
    
    ctx.add_reaction(channel_id, message_id, &reaction).await?;
    println!("Added thumbs up reaction");
    
    // Get users who reacted
    let reaction_users = ctx.get_reaction_users(
        channel_id,
        message_id,
        &reaction,
        None, // cookie
        Some(50), // limit
    ).await?;
    
    println!("Users who reacted:");
    for user in reaction_users.users {
        println!("  - {}", user.username.as_deref().unwrap_or("Unknown"));
    }
    
    // Remove reaction
    ctx.remove_reaction(channel_id, message_id, &reaction).await?;
    println!("Removed reaction");
    
    Ok(())
}
```

### Schedule Management

```rust
async fn create_schedule(
    ctx: Context,
    channel_id: &str,
    name: &str,
    description: &str,
    start_time: &str,
    end_time: &str,
) -> Result<()> {
    let schedule = Schedule {
        id: String::new(), // Will be assigned by server
        name: name.to_string(),
        description: Some(description.to_string()),
        start_timestamp: start_time.to_string(),
        end_timestamp: end_time.to_string(),
        creator: None,
        jump_channel_id: Some(channel_id.to_string()),
        remind_type: "1".to_string(), // Remind before start
    };
    
    // Note: Actual schedule creation would need appropriate API call
    println!("Schedule created: {}", schedule.name);
    Ok(())
}
```

### Permission Checking

```rust
async fn check_user_permissions(
    ctx: Context,
    channel_id: &str,
    user_id: &str,
) -> Result<bool> {
    let permissions = ctx.get_channel_user_permissions(channel_id, user_id).await?;
    
    // Parse permission string (this is simplified)
    let perm_value: u64 = permissions.permissions.parse().unwrap_or(0);
    
    // Check for specific permissions (bit flags)
    const SEND_MESSAGES: u64 = 1 << 11;
    const READ_MESSAGE_HISTORY: u64 = 1 << 16;
    
    let can_send = (perm_value & SEND_MESSAGES) != 0;
    let can_read_history = (perm_value & READ_MESSAGE_HISTORY) != 0;
    
    println!("User permissions in channel:");
    println!("  Can send messages: {}", can_send);
    println!("  Can read history: {}", can_read_history);
    
    Ok(can_send && can_read_history)
}
```

## See Also

- [Client API]../client.md - Main client for bot operations
- [Messages]./messages.md - Message types and handling
- [Guilds & Channels]./guilds-channels.md - Guild and channel management
- [Users & Members]./users-members.md - User and member management