Exemple #1
0
def test_find_channel(channel1):
    """
    Returns channel_id of channel that contains the message_id
    """
    user2 = auth.auth_register("*****@*****.**", "123password", "Elliot", "Rotensttein")
    channel.channel_join(user2["token"], channel1["channel_id"])
    message1 = message.message_send(user2["token"], channel1["channel_id"], "G\'day")
    assert data.find_channel(message1["message_id"]) == channel1["channel_id"]
    
    other.clear()
Exemple #2
0
def execute_victory(info):
    """
    Ends hangman session and prints victory message
    """
    message_id = info['status_message']
    info['is_active'] = False
    channel_id = data.find_channel(message_id)
    data.edit_message(channel_id, message_id, victory_message(info))
    info['status_message'] = None
    info['letters'] = []
Exemple #3
0
def execute_loss(info):
    """
    Ends hangman session and prints loss message
    """
    info['is_active'] = False
    info['failures'] += 1
    message_id = info['status_message']
    channel_id = data.find_channel(message_id)
    data.edit_message(channel_id, message_id, loss_message(info))
    info['status_message'] = None
    info['letters'] = []
Exemple #4
0
def edit_status(info):
    """
    Changes the status message with updated picture and incorrect letters 
    """
    user = data.get_user_info(info['u_id'])
    msg = f"""
    {user['name_first']} has started a hangman!
    Word: {''.join(info['revealed_word'])}
    Incorrect letters guessed: {', '.join(info['letters'])}
    {generate_picture(info)}
    """
    message_id = info['status_message']
    channel_id = data.find_channel(message_id)
    data.edit_message(channel_id, message_id, msg)
Exemple #5
0
def find_channel_with_message(message_id, u_id):
    """
    Will go through every channel and if message_in_channel returns a channel it
    will return it otherwise it raises an Input Error

    Parameters:
        message_id(string): The id of the message being searched for
        user_id(string): The id of the user searching for the message it will return
                         an access error if the user is not an owner of the channel
                         or creator of the message
    Returns:
        channel(channel dictionary): If the channel was found it will return the channel
                                     dictionary
    """
    channel_id = data.find_channel(message_id)
    message = data.get_message(channel_id, message_id)
    if message["u_id"] == u_id or data.check_channel_owner(channel_id, u_id):
        return channel_id
    raise AccessError(description="User is not creator or owner")
Exemple #6
0
 async def follow_subreddit(self, ctx, subreddit):
     """Add a subreddit to follow in this server!
     The channel this command is invoked in will be used
     to post the new submission to the sub.
     Example: `.follow_subreddit <subreddit_name>`"""
     channel = ctx.channel.id
     subreddit = subreddit.lower()
     if '/r/' in subreddit:
         subreddit = subreddit.split('/r/')[-1]
     subreddit_id = get_subreddit_id(subreddit)
     if not subreddit_id:
         add_reddit(subreddit)
         subreddit_id = get_subreddit_id(subreddit)
     add_channel(channel)
     found = find_channel(channel)
     added = add_reddit_channel(found[0], subreddit_id[0])
     if added:
         msg = f"Added {subreddit} to this channel!"
         await ctx.send(embed=success_embed(msg))
     else:
         msg = f"Already added {subreddit} to this channel!"
         await ctx.send(embed=error_embed(msg))
Exemple #7
0
 async def unfollow_subreddit(self, ctx, subreddit):
     """Unfollow a previously followed subreddit.
     Example: `.unfollow_subreddit <subreddit_name>`"""
     channel = ctx.channel.id
     subreddit = subreddit.lower()
     if '/r/' in subreddit:
         subreddit = subreddit.split('/r/')[-1]
     subreddit_id = get_subreddit_id(subreddit)
     if not subreddit_id:
         msg = f"{subreddit} is not found!"
         await ctx.send(embed=error_embed(msg))
         return
     found = find_channel(channel)
     if not found:
         msg = f"{subreddit} is not found!"
         await ctx.send(embed=error_embed(msg))
         return
     removed = remove_channel_from_subreddit(found[0], subreddit_id[0])
     if removed:
         msg = f"Unfollowed {subreddit} in this channel!"
         await ctx.send(embed=success_embed(msg))
     else:
         msg = f"{subreddit} is not followed in this channel"
         await ctx.send(embed=error_embed(msg))